fix: metadata_condition returning all docs when filter matches nothing (#14967)

### What problem does this PR solve?

When _parse_doc_id_filter_with_metadata returns [], the empty list is
falsy so the WHERE id IN (...) clause was silently skipped, causing the
full dataset to be returned instead of an empty result.

Change `if doc_ids:` to `if doc_ids is not None:` in both get_list() and
get_by_kb_id() to distinguish between no filter (None) and a filter that
matched zero documents ([]).

Fixes #14962

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Hamza Amin Khokhar
2026-05-18 15:54:30 +05:00
committed by GitHub
parent 92145dc764
commit 2dbe3b8a62
2 changed files with 3 additions and 3 deletions

View File

@@ -995,7 +995,7 @@ def _parse_doc_id_filter_with_metadata(req, kb_id):
if not doc_ids_filter:
return RetCode.SUCCESS, "", [], return_empty_metadata
return RetCode.SUCCESS, "", list(doc_ids_filter) if doc_ids_filter is not None else [], return_empty_metadata
return RetCode.SUCCESS, "", list(doc_ids_filter) if doc_ids_filter is not None else None, return_empty_metadata
@manager.route("/datasets/<dataset_id>/documents", methods=["DELETE"]) # noqa: F821