Repository navigation
Consolidate set_meta into update_document - #14045
Conversation
📝 WalkthroughWalkthroughThe PR refactors the document metadata update flow by migrating from the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
admin/client/ragflow_client.py (3)
1597-1613: Remove redundant import and unreachable code.
Redundant import:
jsonis already imported at line 16, so the import at line 1598 is unnecessary.Unreachable code: The check at lines 1611-1613 is redundant because
_get_documents_by_idsalready returns an error message whendocsis empty (lines 1584-1585). Ifdoc_error_msgisNone,docsis guaranteed to be non-empty.♻️ Proposed fix
- # Parse JSON string to dict - import json try: meta_fields = json.loads(meta_json_str) except json.JSONDecodeError as e: print(f"Invalid JSON format: {e}") return # Step 1: Get document info to find kb_id (dataset_id) doc_error_msg, docs = self._get_documents_by_ids([doc_id]) if doc_error_msg: print(doc_error_msg) return - if len(docs) == 0: - print(f"no document found for {doc_id}") - return - dataset_id = docs[0].get("kb_id")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@admin/client/ragflow_client.py` around lines 1597 - 1613, Remove the redundant local import of json and the unreachable docs-empty check: delete the "import json" line in the JSON parsing block and remove the if len(docs) == 0 / print(...) / return block, since json is already imported globally and _get_documents_by_ids(doc_id) (used via self._get_documents_by_ids) already returns a doc_error_msg when docs are empty; keep the json.loads(...) try/except and subsequent logic intact.
1567-1587: Add logging for this new flow.The new
_get_documents_by_idsmethod should include logging for error conditions (HTTP failures, non-zero response codes, document not found) to aid debugging and observability. As per coding guidelines, "Add logging for new flows".Also, minor style: add space after colon in type hint (
ids: list[str]).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@admin/client/ragflow_client.py` around lines 1567 - 1587, The _get_documents_by_ids method lacks logging for failure branches and has a minor type-hint spacing style issue; add structured logs (using the module's logger) for the HTTP failure branch (log status_code and request payload/ids), for the non-zero response code branch (log res_json.get("code"), res_json.get("message") and ids), and for the empty docs branch (log that no documents were found along with ids); ensure you call logger.error or logger.warning consistently around the http_client.request call and its response checks (response.status_code, res_json) and adjust the signature to use a spaced type hint ids: list[str].
1625-1640: Add logging for this updated flow.The metadata update operation lacks logging for success and failure cases. Consider adding debug/info level logging before the request and error-level logging for failures to improve observability. As per coding guidelines, "Add logging for new flows".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@admin/client/ragflow_client.py` around lines 1625 - 1640, Add structured logging around the metadata PUT flow: obtain a logger (use self.logger if present or logging.getLogger(__name__)), log an info/debug message before calling self.http_client.request with dataset_id, doc_id and a redacted indication of payload, then replace the print statements with logger.info on success and logger.error on failures including response.status_code, res_json.get("code"), and res_json.get("message"); also catch and logger.exception for any request exceptions around the self.http_client.request call to ensure errors are recorded for debugging.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@admin/client/ragflow_client.py`:
- Around line 1597-1613: Remove the redundant local import of json and the
unreachable docs-empty check: delete the "import json" line in the JSON parsing
block and remove the if len(docs) == 0 / print(...) / return block, since json
is already imported globally and _get_documents_by_ids(doc_id) (used via
self._get_documents_by_ids) already returns a doc_error_msg when docs are empty;
keep the json.loads(...) try/except and subsequent logic intact.
- Around line 1567-1587: The _get_documents_by_ids method lacks logging for
failure branches and has a minor type-hint spacing style issue; add structured
logs (using the module's logger) for the HTTP failure branch (log status_code
and request payload/ids), for the non-zero response code branch (log
res_json.get("code"), res_json.get("message") and ids), and for the empty docs
branch (log that no documents were found along with ids); ensure you call
logger.error or logger.warning consistently around the http_client.request call
and its response checks (response.status_code, res_json) and adjust the
signature to use a spaced type hint ids: list[str].
- Around line 1625-1640: Add structured logging around the metadata PUT flow:
obtain a logger (use self.logger if present or logging.getLogger(__name__)), log
an info/debug message before calling self.http_client.request with dataset_id,
doc_id and a redacted indication of payload, then replace the print statements
with logger.info on success and logger.error on failures including
response.status_code, res_json.get("code"), and res_json.get("message"); also
catch and logger.exception for any request exceptions around the
self.http_client.request call to ensure errors are recorded for debugging.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: afe028e9-ceb3-47cf-9c25-4e6119a862da
📒 Files selected for processing (3)
admin/client/ragflow_client.pyapi/apps/document_app.pytest/testcases/test_web_api/test_chunk_feedback/__init__.py
💤 Files with no reviewable changes (2)
- test/testcases/test_web_api/test_chunk_feedback/init.py
- api/apps/document_app.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14045 +/- ##
=======================================
Coverage 96.66% 96.66%
=======================================
Files 10 10
Lines 690 690
Branches 108 108
=======================================
Hits 667 667
Misses 8 8
Partials 15 15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
### What problem does this PR solve? Consolidate "set_meta" API into "update_document" . Before consolidation Web API: POST /api/v1/document/set_meta Http API - PUT /v1/datasets/<dataset_id>/document/<document_id> After consolidation, Restful API -- PUT /v1/datasets/<dataset_id>/document/<document_id> ### Type of change - [x] Refactoring
### What problem does this PR solve? Consolidate "set_meta" API into "update_document" . Before consolidation Web API: POST /api/v1/document/set_meta Http API - PUT /v1/datasets/<dataset_id>/document/<document_id> After consolidation, Restful API -- PUT /v1/datasets/<dataset_id>/document/<document_id> ### Type of change - [x] Refactoring
### What problem does this PR solve? Consolidate "set_meta" API into "update_document" . Before consolidation Web API: POST /api/v1/document/set_meta Http API - PUT /v1/datasets/<dataset_id>/document/<document_id> After consolidation, Restful API -- PUT /v1/datasets/<dataset_id>/document/<document_id> ### Type of change - [x] Refactoring
### What problem does this PR solve? Consolidate "set_meta" API into "update_document" . Before consolidation Web API: POST /api/v1/document/set_meta Http API - PUT /v1/datasets/<dataset_id>/document/<document_id> After consolidation, Restful API -- PUT /v1/datasets/<dataset_id>/document/<document_id> ### Type of change - [x] Refactoring
What problem does this PR solve?
Consolidate "set_meta" API into "update_document" .
Before consolidation
Web API: POST /api/v1/document/set_meta
Http API - PUT /v1/datasets/<dataset_id>/document/<document_id>
After consolidation, Restful API -- PUT /v1/datasets/<dataset_id>/document/<document_id>
Type of change