Skip to content

Fix: KnowledgebaseService.dfs_update crashes on stored None parser_config values - #15964

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
BaptisteJosh:fix-kb-parser-config-none-merge
Aug 31, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
BaptisteJosh:fix-kb-parser-config-none-merge

Conversation

@BaptisteJosh

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Fixes #15962.

KnowledgebaseService.update_parser_config → dfs_update uses bare assert isinstance(...) checks when merging new parser_config values into the stored config. When a stored value is None, the assert raises a message-less AssertionError, 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/datasets with an explicit parser_config: the create path persists the ParserConfig model's None defaults (table_column_names, table_column_roles, table_column_mode, ...), and rag/app/table.py then writes the discovered column list back through update_parser_config, where the merge of list into stored None crashes. Full analysis, reproduction steps, and traceback are in #15962.

The codebase has two copies of dfs_update. #12815 already fixed the DocumentService copy with safe isinstance conditions (mismatches fall through to overwrite); the KnowledgebaseService copy was never updated. This PR applies the identical pattern there:

# before
if isinstance(v, dict):
    assert isinstance(old[k], dict)
    dfs_update(old[k], v)
elif isinstance(v, list):
    assert isinstance(old[k], list)
    old[k] = list(set(old[k] + v))

# after (same as DocumentService.dfs_update since #12815)
if isinstance(v, dict) and isinstance(old[k], dict):
    dfs_update(old[k], v)
elif isinstance(v, list) and isinstance(old[k], list):
    old[k] = list(set(old[k] + v))

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

  • Bug Fix (non-breaking change which fixes an issue)

…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.
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jun 12, 2026
@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR updates KnowledgebaseService.update_parser_config so nested dictionary and list merges use explicit type checks instead of assertions, allowing mismatched or None stored values to reach the subsequent overwrite or merge logic.

Changes

Parser Config Deep-Merge Type Checking

Layer / File(s) Summary
Replace assertions with explicit type checks in dfs_update
api/db/services/knowledgebase_service.py
Dictionary recursion and list merging now require matching container types through conditional checks, avoiding AssertionError on mismatched or None values.

Estimated code review effort: 2 (Simple) | ~8 minutes

Suggested reviewers: kevinhush

Poem

A rabbit hops through config trees so deep,
Where None once made assertions leap.
Now type checks guard each nested lair,
And mismatched values flow with care. 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix in KnowledgebaseService.dfs_update and matches the code changes.
Description check ✅ Passed The PR description includes the required summary and explains the bug, root cause, fix, and validation.
Linked Issues check ✅ Passed The change addresses #15962 by removing the crashing asserts in dfs_update for stored None parser_config values.
Out of Scope Changes check ✅ Passed The diff stays focused on the parser_config merge fix and introduces no unrelated changes.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟠 Major

dfs_update implementations are not consistent, and #15962 validation isn’t evidenced

  • api/db/services/knowledgebase_service.py merges list values via set-union (old[k] = list(set(old[k] + v))), while api/db/services/document_service.py has no list branch and overwrites lists (old[k] = v).
  • DocumentService.update_parser_config also contains extra raptor key removal logic and an early if not config: return; KnowledgebaseService.update_parser_config does not.
  • No in-repo references/tests for the #15962 CSV-upload reproduction case were found (only unrelated “15962” matches in deepdoc csv files; unit tests only patch KnowledgebaseService.update_parser_config without asserting dfs_update behavior).
🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0d836af and 968cb9b.

📒 Files selected for processing (1)
  • api/db/services/knowledgebase_service.py

@BaptisteJosh

Copy link
Copy Markdown
Contributor Author

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 chunk_method: "table" on a dataset created via the HTTP API with an explicit parser_config fails with a blank "Internal server error while chunking:"; with the change applied, the same document parses to one chunk per row.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
api/db/services/knowledgebase_service.py (1)

355-360: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a regression test for persisted None parser fields.

Cover merging incoming table configuration when existing values such as table_column_names, table_column_roles, or table_column_mode are None, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 968cb9b and bb20907.

📒 Files selected for processing (1)
  • api/db/services/knowledgebase_service.py

@Lynn-Inf Lynn-Inf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Lynn-Inf Lynn-Inf added the ci Continue Integration label Aug 31, 2026
@JinHai-CN
JinHai-CN merged commit 5af3bf2 into infiniflow:main Aug 31, 2026
6 checks passed
mill413 pushed a commit to mill413/ragflow that referenced this pull request Sep 3, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

3 participants