Repository navigation
Fix: KnowledgebaseService.dfs_update crashes on stored None parser_config values - #15964
Conversation
…nfig values (infiniflow#15962) Apply the same safe isinstance merge that infiniflow#12815 applied to the DocumentService copy of dfs_update. Datasets created via POST /api/v1/datasets with an explicit parser_config persist the ParserConfig model's None defaults (table_column_names et al.); the table chunker's write-back then hit the bare assert and every table parse failed with a blank error message.
📝 WalkthroughWalkthroughThis PR updates ChangesParser Config Deep-Merge Type Checking
Estimated code review effort: 2 (Simple) | ~8 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
api/db/services/knowledgebase_service.py (1)
314-325:⚠️ Potential issue | 🟠 Majordfs_update implementations are not consistent, and
#15962validation isn’t evidenced
api/db/services/knowledgebase_service.pymerges list values via set-union (old[k] = list(set(old[k] + v))), whileapi/db/services/document_service.pyhas no list branch and overwrites lists (old[k] = v).DocumentService.update_parser_configalso contains extraraptorkey removal logic and an earlyif not config: return;KnowledgebaseService.update_parser_configdoes not.- No in-repo references/tests for the
#15962CSV-upload reproduction case were found (only unrelated “15962” matches in deepdoc csv files; unit tests only patchKnowledgebaseService.update_parser_configwithout assertingdfs_updatebehavior).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@api/db/services/knowledgebase_service.py` around lines 314 - 325, dfs_update currently behaves differently between services and lacks the `#15962` CSV-upload validation: unify dfs_update behavior (choose and document whether lists are overwritten or merged) by updating the dfs_update implementation in api/db/services/knowledgebase_service.py to match the semantics used by api/db/services/document_service.py (or vice versa) for list handling in the list branch inside dfs_update; in addition, make KnowledgebaseService.update_parser_config follow the same control flow as DocumentService.update_parser_config by adding the early "if not config: return" guard and the raptor key removal logic, and add/adjust validation logic referenced by `#15962` so uploaded CSVs are normalized before merging; finally add unit tests that call KnowledgebaseService.update_parser_config and/or dfs_update to assert the chosen list merge behavior and the CSV-upload reproduction case.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@api/db/services/knowledgebase_service.py`:
- Around line 314-325: dfs_update currently behaves differently between services
and lacks the `#15962` CSV-upload validation: unify dfs_update behavior (choose
and document whether lists are overwritten or merged) by updating the dfs_update
implementation in api/db/services/knowledgebase_service.py to match the
semantics used by api/db/services/document_service.py (or vice versa) for list
handling in the list branch inside dfs_update; in addition, make
KnowledgebaseService.update_parser_config follow the same control flow as
DocumentService.update_parser_config by adding the early "if not config: return"
guard and the raptor key removal logic, and add/adjust validation logic
referenced by `#15962` so uploaded CSVs are normalized before merging; finally add
unit tests that call KnowledgebaseService.update_parser_config and/or dfs_update
to assert the chosen list merge behavior and the CSV-upload reproduction case.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 37c03d04-d398-499a-9e7c-e6d46fbbc8f1
📒 Files selected for processing (1)
api/db/services/knowledgebase_service.py
|
Re the CodeRabbit findings, for the human reviewer's convenience:
Validation: reproduced on v0.25.6 per the steps in #15962 — without this change, parsing any CSV with |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
api/db/services/knowledgebase_service.py (1)
355-360: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd a regression test for persisted
Noneparser fields.Cover merging incoming table configuration when existing values such as
table_column_names,table_column_roles, ortable_column_modeareNone, and assert that the merge completes with the expected values. This protects the reported crash path and the existing list-union behavior.As per coding guidelines: “Preserve valid behavior with focused tests” and “Run the narrowest relevant test, lint, or build command after a change.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@api/db/services/knowledgebase_service.py` around lines 355 - 360, Add a focused regression test for the merge logic surrounding dfs_update, using persisted None values for table_column_names, table_column_roles, and table_column_mode alongside incoming table configuration. Assert the merge completes without crashing and produces the expected incoming values while preserving the existing list-union behavior, then run the narrowest relevant test command.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@api/db/services/knowledgebase_service.py`:
- Around line 355-360: Add a focused regression test for the merge logic
surrounding dfs_update, using persisted None values for table_column_names,
table_column_roles, and table_column_mode alongside incoming table
configuration. Assert the merge completes without crashing and produces the
expected incoming values while preserving the existing list-union behavior, then
run the narrowest relevant test command.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d18f55a2-1fd0-4e28-aa11-3408728721cb
📒 Files selected for processing (1)
api/db/services/knowledgebase_service.py
Lynn-Inf
left a comment
There was a problem hiding this comment.
LGTM — the change is correct and I agree with dropping the bare assert. The original intent is reasonable (guard the shape invariant before merging dict-into-dict / list-into-list), but assert is the wrong tool here: it's stripped under
python -O, it conflates a legitimate "unset" (None, from ParserConfig defaults being persisted) with actual corruption, and a message-less AssertionError is useless for diagnosis. The fall-through to old[k] = v is also semantically
consistent with the if k not in old branch right above it. Aligning this copy with DocumentService.dfs_update (already using the and pattern since #12815) removes a real divergence between the two helpers — and this PR keeps the list-union
behaviour that the DocumentService copy doesn't even have, so it's the conservative direction.
Non-blocking: the bare and makes a genuine shape mismatch silent. If you want to keep the original intent of surfacing schema drift without crashing, consider logging a warning before overwriting, e.g. logging.warning("parser_config key %r: expected list, found %s; overwriting", k, type(old[k]).__name__) in the mismatch branches. That preserves operator visibility while still self-healing.
Unrelated observation (out of scope here, worth a separate issue): old[k] = list(set(old[k] + v)) is unsafe for order-sensitive list values like table_column_names — set drops ordering and duplicates, and since Python randomises string
hashing per process, the resulting order isn't even stable across restarts. That's pre-existing behaviour this PR doesn't touch, but it looks like a latent bug for table parsing.
…nfig values (infiniflow#15964) Fix infiniflow#15962 — replace bare assert isinstance in KnowledgebaseService.dfs_update with safe conditions. Stored None values no longer crash table-parser parses. Matches DocumentService fix from infiniflow#12815.
What problem does this PR solve?
Fixes #15962.
KnowledgebaseService.update_parser_config→dfs_updateuses bareassert isinstance(...)checks when merging newparser_configvalues into the stored config. When a stored value isNone, the assert raises a message-lessAssertionError, so the failure surfaces in the document log as a blank[ERROR]Internal server error while chunking:.This is hit on every table-parser parse for datasets created via
POST /api/v1/datasetswith an explicitparser_config: the create path persists theParserConfigmodel'sNonedefaults (table_column_names,table_column_roles,table_column_mode, ...), andrag/app/table.pythen writes the discovered column list back throughupdate_parser_config, where the merge oflistinto storedNonecrashes. Full analysis, reproduction steps, and traceback are in #15962.The codebase has two copies of
dfs_update. #12815 already fixed theDocumentServicecopy with safeisinstanceconditions (mismatches fall through to overwrite); theKnowledgebaseServicecopy was never updated. This PR applies the identical pattern there:Verified against v0.25.6: with this change applied, the reproduction CSV from #15962 parses successfully (one chunk per row); without it, the parse fails as described.
Type of change