Skip to content

Commit ad789f5

Browse files
authored
Fix list files (infiniflow#13960)
### What problem does this PR solve? As title. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Standardized the query parameter used when listing documents so listings behave consistently across the web and client interfaces. * Clarified the error message shown when a required dataset ID is missing to give clearer guidance to users. * **Tests** * Updated test coverage to reflect the standardized dataset identifier usage. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
1 parent b8764cf commit ad789f5

10 files changed

Lines changed: 37 additions & 37 deletions

File tree

admin/client/ragflow_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ def _wait_parse_done(self, dataset_name: str, dataset_id: str):
16851685
time.sleep(0.5)
16861686

16871687
def _list_documents(self, dataset_name: str, dataset_id: str):
1688-
response = self.http_client.request("POST", f"/document/list?kb_id={dataset_id}", use_api_base=False,
1688+
response = self.http_client.request("POST", f"/document/list?id={dataset_id}", use_api_base=False,
16891689
auth_kind="web")
16901690
res_json = response.json()
16911691
if response.status_code != 200:

api/apps/document_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ async def create():
240240
@manager.route("/list", methods=["POST"]) # noqa: F821
241241
@login_required
242242
async def list_docs():
243-
kb_id = request.args.get("kb_id")
243+
kb_id = request.args.get("id")
244244
if not kb_id:
245-
return get_json_result(data=False, message='Lack of "KB ID"', code=RetCode.ARGUMENT_ERROR)
245+
return get_json_result(data=False, message='Dataset ID is required for listing files.', code=RetCode.ARGUMENT_ERROR)
246246
tenants = UserTenantService.query(user_id=current_user.id)
247247
for tenant in tenants:
248248
if KnowledgebaseService.query(tenant_id=tenant.tenant_id, id=kb_id):

sdk/python/test/test_frontend_api/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def upload_file(auth, dataset_id, path):
6969

7070
def list_document(auth, dataset_id):
7171
authorization = {"Authorization": auth}
72-
url = f"{HOST_ADDRESS}/v1/document/list?kb_id={dataset_id}"
72+
url = f"{HOST_ADDRESS}/v1/document/list?id={dataset_id}"
7373
json = {}
7474
res = requests.post(url=url, headers=authorization, json=json)
7575
return res.json()

test/testcases/test_web_api/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
@wait_for(30, 1, "Document parsing timeout")
5151
def condition(_auth, _kb_id):
52-
res = list_documents(_auth, {"kb_id": _kb_id})
52+
res = list_documents(_auth, {"id": _kb_id})
5353
for doc in res["data"]["docs"]:
5454
if doc["run"] != "3":
5555
return False

test/testcases/test_web_api/test_chunk_app/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
@wait_for(30, 1, "Document parsing timeout")
2626
def condition(_auth, _kb_id):
27-
res = list_documents(_auth, {"kb_id": _kb_id})
27+
res = list_documents(_auth, {"id": _kb_id})
2828
for doc in res["data"]["docs"]:
2929
if doc["run"] != "3":
3030
return False

test/testcases/test_web_api/test_document_app/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def decorator(func):
3434
@pytest.fixture(scope="function")
3535
def add_document_func(request, WebApiAuth, add_dataset, ragflow_tmp_dir):
3636
def cleanup():
37-
res = list_documents(WebApiAuth, {"kb_id": dataset_id})
37+
res = list_documents(WebApiAuth, {"id": dataset_id})
3838
for doc in res["data"]["docs"]:
3939
delete_document(WebApiAuth, {"doc_id": doc["id"]})
4040

@@ -47,7 +47,7 @@ def cleanup():
4747
@pytest.fixture(scope="class")
4848
def add_documents(request, WebApiAuth, add_dataset, ragflow_tmp_dir):
4949
def cleanup():
50-
res = list_documents(WebApiAuth, {"kb_id": dataset_id})
50+
res = list_documents(WebApiAuth, {"id": dataset_id})
5151
for doc in res["data"]["docs"]:
5252
delete_document(WebApiAuth, {"doc_id": doc["id"]})
5353

@@ -60,7 +60,7 @@ def cleanup():
6060
@pytest.fixture(scope="function")
6161
def add_documents_func(request, WebApiAuth, add_dataset_func, ragflow_tmp_dir):
6262
def cleanup():
63-
res = list_documents(WebApiAuth, {"kb_id": dataset_id})
63+
res = list_documents(WebApiAuth, {"id": dataset_id})
6464
for doc in res["data"]["docs"]:
6565
delete_document(WebApiAuth, {"doc_id": doc["id"]})
6666

test/testcases/test_web_api/test_document_app/test_list_documents.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TestAuthorization:
3434
],
3535
)
3636
def test_invalid_auth(self, invalid_auth, expected_code, expected_message):
37-
res = list_documents(invalid_auth, {"kb_id": "dataset_id"})
37+
res = list_documents(invalid_auth, {"id": "dataset_id"})
3838
assert res["code"] == expected_code
3939
assert res["message"] == expected_message
4040

@@ -43,7 +43,7 @@ class TestDocumentsList:
4343
@pytest.mark.p1
4444
def test_default(self, WebApiAuth, add_documents):
4545
kb_id, _ = add_documents
46-
res = list_documents(WebApiAuth, {"kb_id": kb_id})
46+
res = list_documents(WebApiAuth, {"id": kb_id})
4747
assert res["code"] == 0
4848
assert len(res["data"]["docs"]) == 5
4949
assert res["data"]["total"] == 5
@@ -57,7 +57,7 @@ def test_default(self, WebApiAuth, add_documents):
5757
],
5858
)
5959
def test_invalid_dataset_id(self, WebApiAuth, kb_id, expected_code, expected_message):
60-
res = list_documents(WebApiAuth, {"kb_id": kb_id})
60+
res = list_documents(WebApiAuth, {"id": kb_id})
6161
assert res["code"] == expected_code
6262
assert res["message"] == expected_message
6363

@@ -76,7 +76,7 @@ def test_invalid_dataset_id(self, WebApiAuth, kb_id, expected_code, expected_mes
7676
)
7777
def test_page(self, WebApiAuth, add_documents, params, expected_code, expected_page_size, expected_message):
7878
kb_id, _ = add_documents
79-
res = list_documents(WebApiAuth, {"kb_id": kb_id, **params})
79+
res = list_documents(WebApiAuth, {"id": kb_id, **params})
8080
assert res["code"] == expected_code, res
8181
if expected_code == 0:
8282
assert len(res["data"]["docs"]) == expected_page_size, res
@@ -99,7 +99,7 @@ def test_page(self, WebApiAuth, add_documents, params, expected_code, expected_p
9999
)
100100
def test_page_size(self, WebApiAuth, add_documents, params, expected_code, expected_page_size, expected_message):
101101
kb_id, _ = add_documents
102-
res = list_documents(WebApiAuth, {"kb_id": kb_id, **params})
102+
res = list_documents(WebApiAuth, {"id": kb_id, **params})
103103
assert res["code"] == expected_code, res
104104
if expected_code == 0:
105105
assert len(res["data"]["docs"]) == expected_page_size, res
@@ -119,7 +119,7 @@ def test_page_size(self, WebApiAuth, add_documents, params, expected_code, expec
119119
)
120120
def test_orderby(self, WebApiAuth, add_documents, params, expected_code, assertions, expected_message):
121121
kb_id, _ = add_documents
122-
res = list_documents(WebApiAuth, {"kb_id": kb_id, **params})
122+
res = list_documents(WebApiAuth, {"id": kb_id, **params})
123123
assert res["code"] == expected_code, res
124124
if expected_code == 0:
125125
if callable(assertions):
@@ -144,7 +144,7 @@ def test_orderby(self, WebApiAuth, add_documents, params, expected_code, asserti
144144
)
145145
def test_desc(self, WebApiAuth, add_documents, params, expected_code, assertions, expected_message):
146146
kb_id, _ = add_documents
147-
res = list_documents(WebApiAuth, {"kb_id": kb_id, **params})
147+
res = list_documents(WebApiAuth, {"id": kb_id, **params})
148148
assert res["code"] == expected_code, res
149149
if expected_code == 0:
150150
if callable(assertions):
@@ -165,7 +165,7 @@ def test_desc(self, WebApiAuth, add_documents, params, expected_code, assertions
165165
)
166166
def test_keywords(self, WebApiAuth, add_documents, params, expected_num):
167167
kb_id, _ = add_documents
168-
res = list_documents(WebApiAuth, {"kb_id": kb_id, **params})
168+
res = list_documents(WebApiAuth, {"id": kb_id, **params})
169169
assert res["code"] == 0, res
170170
assert len(res["data"]["docs"]) == expected_num, res
171171
assert res["data"]["total"] == expected_num, res
@@ -210,11 +210,11 @@ async def fake_request_json():
210210
monkeypatch.setattr(module, "get_request_json", fake_request_json)
211211
res = _run(module.list_docs())
212212
assert res["code"] == 101
213-
assert res["message"] == 'Lack of "KB ID"'
213+
assert res["message"] == 'Dataset ID is required for listing files.'
214214

215215
def test_unauthorized_dataset(self, document_app_module, monkeypatch):
216216
module = document_app_module
217-
self._set_args(module, monkeypatch, kb_id="kb1")
217+
self._set_args(module, monkeypatch, id="kb1")
218218
monkeypatch.setattr(module.UserTenantService, "query", lambda **_kwargs: [SimpleNamespace(tenant_id="tenant1")])
219219
monkeypatch.setattr(module.KnowledgebaseService, "query", lambda **_kwargs: False)
220220

@@ -228,7 +228,7 @@ async def fake_request_json():
228228

229229
def test_return_empty_metadata_flags(self, document_app_module, monkeypatch):
230230
module = document_app_module
231-
self._set_args(module, monkeypatch, kb_id="kb1")
231+
self._set_args(module, monkeypatch, id="kb1")
232232
self._allow_kb(module, monkeypatch)
233233
monkeypatch.setattr(module.DocumentService, "get_by_kb_id", lambda *_args, **_kwargs: ([], 0))
234234

@@ -248,7 +248,7 @@ async def fake_request_json_empty():
248248

249249
def test_invalid_filters(self, document_app_module, monkeypatch):
250250
module = document_app_module
251-
self._set_args(module, monkeypatch, kb_id="kb1")
251+
self._set_args(module, monkeypatch, id="kb1")
252252
self._allow_kb(module, monkeypatch)
253253

254254
async def fake_request_json():
@@ -269,7 +269,7 @@ async def fake_request_json_types():
269269

270270
def test_invalid_metadata_types(self, document_app_module, monkeypatch):
271271
module = document_app_module
272-
self._set_args(module, monkeypatch, kb_id="kb1")
272+
self._set_args(module, monkeypatch, id="kb1")
273273
self._allow_kb(module, monkeypatch)
274274

275275
async def fake_request_json():
@@ -290,7 +290,7 @@ async def fake_request_json_meta():
290290

291291
def test_metadata_condition_empty_result(self, document_app_module, monkeypatch):
292292
module = document_app_module
293-
self._set_args(module, monkeypatch, kb_id="kb1")
293+
self._set_args(module, monkeypatch, id="kb1")
294294
self._allow_kb(module, monkeypatch)
295295
monkeypatch.setattr(module.DocMetadataService, "get_flatted_meta_by_kbs", lambda *_args, **_kwargs: {})
296296
monkeypatch.setattr(module, "meta_filter", lambda *_args, **_kwargs: set())
@@ -305,7 +305,7 @@ async def fake_request_json():
305305

306306
def test_metadata_values_intersection(self, document_app_module, monkeypatch):
307307
module = document_app_module
308-
self._set_args(module, monkeypatch, kb_id="kb1")
308+
self._set_args(module, monkeypatch, id="kb1")
309309
self._allow_kb(module, monkeypatch)
310310
metas = {
311311
"author": {"alice": ["doc1", "doc2"]},
@@ -334,7 +334,7 @@ async def fake_request_json():
334334

335335
def test_metadata_intersection_empty(self, document_app_module, monkeypatch):
336336
module = document_app_module
337-
self._set_args(module, monkeypatch, kb_id="kb1")
337+
self._set_args(module, monkeypatch, id="kb1")
338338
self._allow_kb(module, monkeypatch)
339339
metas = {
340340
"author": {"alice": ["doc1"]},
@@ -352,7 +352,7 @@ async def fake_request_json():
352352

353353
def test_desc_time_and_schema(self, document_app_module, monkeypatch):
354354
module = document_app_module
355-
self._set_args(module, monkeypatch, kb_id="kb1", desc="false", create_time_from="150", create_time_to="250")
355+
self._set_args(module, monkeypatch, id="kb1", desc="false", create_time_from="150", create_time_to="250")
356356
self._allow_kb(module, monkeypatch)
357357

358358
docs = [
@@ -377,7 +377,7 @@ async def fake_request_json():
377377

378378
def test_exception_path(self, document_app_module, monkeypatch):
379379
module = document_app_module
380-
self._set_args(module, monkeypatch, kb_id="kb1")
380+
self._set_args(module, monkeypatch, id="kb1")
381381
self._allow_kb(module, monkeypatch)
382382

383383
def raise_error(*_args, **_kwargs):

test/testcases/test_web_api/test_document_app/test_paser_documents.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _run(coro):
3030

3131
@wait_for(30, 1, "Document parsing timeout")
3232
def condition(_auth, _kb_id, _document_ids=None):
33-
res = list_documents(_auth, {"kb_id": _kb_id})
33+
res = list_documents(_auth, {"id": _kb_id})
3434
target_docs = res["data"]["docs"]
3535

3636
if _document_ids is None:
@@ -48,7 +48,7 @@ def condition(_auth, _kb_id, _document_ids=None):
4848

4949

5050
def validate_document_parse_done(auth, _kb_id, _document_ids):
51-
res = list_documents(auth, {"kb_id": _kb_id})
51+
res = list_documents(auth, {"id": _kb_id})
5252
for doc in res["data"]["docs"]:
5353
if doc["id"] not in _document_ids:
5454
continue
@@ -60,7 +60,7 @@ def validate_document_parse_done(auth, _kb_id, _document_ids):
6060

6161

6262
def validate_document_parse_cancel(auth, _kb_id, _document_ids):
63-
res = list_documents(auth, {"kb_id": _kb_id})
63+
res = list_documents(auth, {"id": _kb_id})
6464
for doc in res["data"]["docs"]:
6565
if doc["id"] not in _document_ids:
6666
continue
@@ -151,7 +151,7 @@ def test_duplicate_parse(self, WebApiAuth, add_documents_func):
151151
def test_parse_100_files(WebApiAuth, add_dataset_func, tmp_path):
152152
@wait_for(100, 1, "Document parsing timeout")
153153
def condition(_auth, _kb_id, _document_num):
154-
res = list_documents(_auth, {"kb_id": _kb_id, "page_size": _document_num})
154+
res = list_documents(_auth, {"id": _kb_id, "page_size": _document_num})
155155
for doc in res["data"]["docs"]:
156156
if doc["run"] != "3":
157157
return False
@@ -172,7 +172,7 @@ def condition(_auth, _kb_id, _document_num):
172172
def test_concurrent_parse(WebApiAuth, add_dataset_func, tmp_path):
173173
@wait_for(120, 1, "Document parsing timeout")
174174
def condition(_auth, _kb_id, _document_num):
175-
res = list_documents(_auth, {"kb_id": _kb_id, "page_size": _document_num})
175+
res = list_documents(_auth, {"id": _kb_id, "page_size": _document_num})
176176
for doc in res["data"]["docs"]:
177177
if doc["run"] != "3":
178178
return False
@@ -305,7 +305,7 @@ class TestDocumentsParseStop:
305305
def test_basic_scenarios(self, WebApiAuth, add_documents_func, payload, expected_code, expected_message):
306306
@wait_for(30, 1, "Document parsing timeout")
307307
def condition(_auth, _kb_id, _doc_ids):
308-
res = list_documents(_auth, {"kb_id": _kb_id})
308+
res = list_documents(_auth, {"id": _kb_id})
309309
for doc in res["data"]["docs"]:
310310
if doc["id"] in _doc_ids:
311311
if doc["run"] != "3":

test/testcases/test_web_api/test_document_app/test_rm_documents.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_basic_scenarios(self, WebApiAuth, add_documents_func, payload, expected
6363
if res["code"] != 0:
6464
assert res["message"] == expected_message, res
6565

66-
res = list_documents(WebApiAuth, {"kb_id": kb_id})
66+
res = list_documents(WebApiAuth, {"id": kb_id})
6767
assert len(res["data"]["docs"]) == remaining, res
6868
assert res["data"]["total"] == remaining, res
6969

@@ -124,12 +124,12 @@ def test_delete_100(WebApiAuth, add_dataset, tmp_path):
124124
documents_num = 100
125125
kb_id = add_dataset
126126
document_ids = bulk_upload_documents(WebApiAuth, kb_id, documents_num, tmp_path)
127-
res = list_documents(WebApiAuth, {"kb_id": kb_id})
127+
res = list_documents(WebApiAuth, {"id": kb_id})
128128
assert res["data"]["total"] == documents_num, res
129129

130130
for doc_id in document_ids:
131131
res = delete_document(WebApiAuth, {"doc_id": doc_id})
132132
assert res["code"] == 0, res
133133

134-
res = list_documents(WebApiAuth, {"kb_id": kb_id})
134+
res = list_documents(WebApiAuth, {"id": kb_id})
135135
assert res["data"]["total"] == 0, res

test/testcases/test_web_api/test_kb_app/test_kb_pipeline_tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _condition():
7575
def _wait_for_docs_parsed(auth, kb_id, timeout=60):
7676
@wait_for(timeout, 2, "Document parsing timeout")
7777
def _condition():
78-
res = list_documents(auth, {"kb_id": kb_id})
78+
res = list_documents(auth, {"id": kb_id})
7979
if res["code"] != 0:
8080
return False
8181
for doc in res["data"]["docs"]:

0 commit comments

Comments
 (0)