-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Refactor: Consolidation WEB API & HTTP API for document infos #14239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
375edba
1cf35bd
93454f3
b91b9df
d0bdcb0
f251468
ca02eaa
d52bdba
57dfaa7
e5fc37c
179fea0
a6ca87f
3a5cd39
80914f6
4e147af
c239715
0eb4304
09c5f02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,7 @@ def test_filter_auth_invalid(self, invalid_auth, expected_code, expected_fragmen | |
| @pytest.mark.p2 | ||
| @pytest.mark.parametrize("invalid_auth, expected_code, expected_fragment", INVALID_AUTH_CASES) | ||
| def test_infos_auth_invalid(self, invalid_auth, expected_code, expected_fragment): | ||
| res = document_infos(invalid_auth, {"doc_ids": ["doc_id"]}) | ||
| res = document_infos(invalid_auth, "kb_id", {"doc_ids": ["doc_id"]}) | ||
| assert res["code"] == expected_code, res | ||
|
Comment on lines
46
to
48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the remaining Line 47 still uses Suggested test update- res = document_infos(invalid_auth, "kb_id", {"doc_ids": ["doc_id"]})
+ res = document_infos(invalid_auth, "kb_id", {"ids": ["doc_id"]})
...
- def test_infos_invalid_doc_id(self, WebApiAuth):
- res = document_infos(WebApiAuth, {"doc_ids": ["invalid_id"]})
+ def test_infos_invalid_doc_id(self, WebApiAuth, add_document_func):
+ dataset_id, _ = add_document_func
+ res = document_infos(WebApiAuth, dataset_id, {"ids": ["invalid_id"]})Also applies to: 177-180 🤖 Prompt for AI Agents |
||
| assert expected_fragment in res["message"], res | ||
|
|
||
|
|
@@ -91,11 +91,12 @@ def test_filter(self, WebApiAuth, add_dataset_func): | |
|
|
||
| @pytest.mark.p2 | ||
| def test_infos(self, WebApiAuth, add_document_func): | ||
| _, doc_id = add_document_func | ||
| res = document_infos(WebApiAuth, {"doc_ids": [doc_id]}) | ||
| dataset_id, doc_id = add_document_func | ||
| res = document_infos(WebApiAuth, dataset_id, {"ids": [doc_id]}) | ||
| assert res["code"] == 0, res | ||
| assert len(res["data"]) == 1, res | ||
| assert res["data"][0]["id"] == doc_id, res | ||
| docs = res["data"]["docs"] | ||
| assert len(docs) == 1, docs | ||
| assert docs[0]["id"] == doc_id, res | ||
|
|
||
| ## The inputs has been changed to add 'doc_ids' | ||
| ## TODO: | ||
|
|
@@ -138,20 +139,22 @@ def test_infos(self, WebApiAuth, add_document_func): | |
|
|
||
| @pytest.mark.p2 | ||
| def test_change_status(self, WebApiAuth, add_document_func): | ||
| _, doc_id = add_document_func | ||
| dataset_id, doc_id = add_document_func | ||
| res = document_change_status(WebApiAuth, {"doc_ids": [doc_id], "status": "1"}) | ||
|
|
||
| assert res["code"] == 0, res | ||
| assert res["data"][doc_id]["status"] == "1", res | ||
| info_res = document_infos(WebApiAuth, {"doc_ids": [doc_id]}) | ||
| info_res = document_infos(WebApiAuth, dataset_id, {"ids": [doc_id]}) | ||
|
|
||
| assert info_res["code"] == 0, info_res | ||
| assert info_res["data"][0]["status"] == "1", info_res | ||
| assert info_res["data"]["docs"][0]["status"] == "1", info_res | ||
|
|
||
|
|
||
| class TestDocumentMetadataNegative: | ||
| @pytest.mark.p2 | ||
| def test_filter_missing_kb_id(self, WebApiAuth, add_document_func): | ||
| kb_id, doc_id = add_document_func | ||
| res = document_filter(WebApiAuth, "", {"doc_ids": [doc_id]}) | ||
| res = document_filter(WebApiAuth, "", {"ids": [doc_id]}) | ||
| assert res["code"] == 100, res | ||
| assert "<MethodNotAllowed '405: Method Not Allowed'>" == res["message"], res | ||
|
|
||
|
|
@@ -228,26 +231,6 @@ def _allow_kb(self, module, monkeypatch, kb_id="kb1", tenant_id="tenant1"): | |
| monkeypatch.setattr(module.UserTenantService, "query", lambda **_kwargs: [SimpleNamespace(tenant_id=tenant_id)]) | ||
| monkeypatch.setattr(module.KnowledgebaseService, "query", lambda **_kwargs: True if _kwargs.get("id") == kb_id else False) | ||
|
|
||
|
|
||
| def test_infos_meta_fields(self, document_app_module, monkeypatch): | ||
| module = document_app_module | ||
| monkeypatch.setattr(module.DocumentService, "accessible", lambda *_args, **_kwargs: True) | ||
|
|
||
| class _Docs: | ||
| def dicts(self): | ||
| return [{"id": "doc1"}] | ||
|
|
||
| monkeypatch.setattr(module.DocumentService, "get_by_ids", lambda _ids: _Docs()) | ||
| monkeypatch.setattr(module.DocMetadataService, "get_document_metadata", lambda _doc_id: {"author": "alice"}) | ||
|
|
||
| async def fake_request_json(): | ||
| return {"doc_ids": ["doc1"]} | ||
|
|
||
| monkeypatch.setattr(module, "get_request_json", fake_request_json) | ||
| res = _run(module.doc_infos()) | ||
| assert res["code"] == 0 | ||
| assert res["data"][0]["meta_fields"]["author"] == "alice" | ||
|
|
||
| def test_metadata_update_missing_kb_id(self, document_app_module, monkeypatch): | ||
| module = document_app_module | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 96
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 828
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 1334
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 105
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 1043
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 1270
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 1471
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 2256
Fix
paramsinitialization to support repeated query parameters.Line 96 initializes
params = {}, but line 100 calls.append()on it. Dicts don't have.append(), so the firstdoc_idsrequest fails withAttributeError. The fix is to initializeparams = []and convert the single-ID branch to append as well:Fix
Additionally, ruff reports 4 whitespace linting violations (W293) at lines 81, 87, 94, 104. Run
ruff check --fixto resolve them per the coding guidelines.🤖 Prompt for AI Agents