Repository navigation
Fix metadata parsing regression for upgraded v0.24 datasets - #14383
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@rag/svr/task_executor.py`:
- Around line 417-429: metadata_conf can be a dict that lacks a proper
"properties" dict, which then falls through to the else branch where
list(metadata_conf) produces a list of keys and breaks metadata handling; update
the logic around metadata_conf/built_in_metadata to explicitly handle three
cases: (1) if metadata_conf is a dict and metadata_conf.get("properties") is a
dict -> merge properties as currently done using
turn2jsonschema(built_in_metadata), (2) if metadata_conf is a dict but
properties is missing or not a dict -> coerce into a proper object-schema by
creating a new dict with "type":"object" and "properties" equal to
turn2jsonschema(built_in_metadata).get("properties", {}) merged with any
existing metadata_conf entries (or log and preserve non-properties fields under
a safe key), and (3) if metadata_conf is an iterable/list -> keep the existing
list concat path; also add a debug-level log call indicating which branch was
taken (referencing metadata_conf, built_in_metadata, and the use of
turn2jsonschema) so flows are observable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2ae756fb-facf-435f-ac35-98a528c74e5e
📒 Files selected for processing (1)
rag/svr/task_executor.py
| metadata_conf = task["parser_config"].get("metadata", []) | ||
| built_in_metadata = list(task["parser_config"].get("built_in_metadata") or []) | ||
| if isinstance(metadata_conf, dict) and isinstance(metadata_conf.get("properties"), dict): | ||
| if built_in_metadata: | ||
| metadata_conf = { | ||
| **metadata_conf, | ||
| "properties": { | ||
| **metadata_conf.get("properties", {}), | ||
| **turn2jsonschema(built_in_metadata).get("properties", {}), | ||
| }, | ||
| } | ||
| else: | ||
| metadata_conf = list(metadata_conf) + built_in_metadata |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify get_llm_cache handles dict-typed config_args (since metadata_conf may now be a dict).
ast-grep --pattern $'def get_llm_cache($$$):
$$$'
rg -nP --type=py -C3 '\bget_llm_cache\s*\('Repository: infiniflow/ragflow
Length of output: 4297
🏁 Script executed:
# Find turn2jsonschema implementation
rg -nP --type=py -A10 'def turn2jsonschema' | head -40Repository: infiniflow/ragflow
Length of output: 828
🏁 Script executed:
# Check the metadata_utils module referenced in review
find . -name metadata_utils.py -o -name "*metadata*" | grep -v __pycache__Repository: infiniflow/ragflow
Length of output: 1150
🏁 Script executed:
# Examine the context around lines 417-429 in task_executor.py more broadly
sed -n '410,450p' rag/svr/task_executor.pyRepository: infiniflow/ragflow
Length of output: 2288
🏁 Script executed:
# Find all metadata config sources to understand what values could actually be passed
rg -nP --type=py 'parser_config.*metadata|metadata.*parser_config' -B2 -A2 | head -60Repository: infiniflow/ragflow
Length of output: 4296
🏁 Script executed:
# Get complete turn2jsonschema function
sed -n '328,365p' common/metadata_utils.pyRepository: infiniflow/ragflow
Length of output: 699
🏁 Script executed:
# Check _is_json_schema and _is_metadata_list implementations
rg -nP 'def _is_json_schema|def _is_metadata_list' common/metadata_utils.py -A10Repository: infiniflow/ragflow
Length of output: 750
🏁 Script executed:
# Look for any error handling or fallback in turn2jsonschema
rg -nP 'def turn2jsonschema' common/metadata_utils.py -A30Repository: infiniflow/ragflow
Length of output: 763
Hardening needed: list(dict) edge case produces invalid metadata config.
When metadata_conf is a dict but doesn't match the JSON schema validation (e.g., {"type": "object"} without a properties dict, or a dict with non-dict properties), the else branch at line 429 executes list(metadata_conf) + built_in_metadata. Since list(dict) returns the dict's keys (e.g., ["type"]), this produces a malformed list like ["type", {key: "...", desc: "..."}, ...] that fails the _is_metadata_list() check in turn2jsonschema(), causing it to return {} and silently disabling metadata extraction rather than failing or recovering.
The current if-guard at line 419 correctly handles dicts with properties dicts, but unintended dict shapes slip through to the problematic else branch. Restructure to explicitly handle all dict cases:
🛠️ Suggested fix
- if isinstance(metadata_conf, dict) and isinstance(metadata_conf.get("properties"), dict):
- if built_in_metadata:
- metadata_conf = {
- **metadata_conf,
- "properties": {
- **metadata_conf.get("properties", {}),
- **turn2jsonschema(built_in_metadata).get("properties", {}),
- },
- }
- else:
- metadata_conf = list(metadata_conf) + built_in_metadata
+ if isinstance(metadata_conf, dict):
+ # Merge built-in metadata into schema (post-upgrade format).
+ if built_in_metadata:
+ props = metadata_conf.get("properties", {}) if isinstance(metadata_conf.get("properties"), dict) else {}
+ metadata_conf = {
+ **metadata_conf,
+ "properties": {
+ **props,
+ **turn2jsonschema(built_in_metadata).get("properties", {}),
+ },
+ }
+ elif isinstance(metadata_conf, list):
+ metadata_conf = metadata_conf + built_in_metadata
+ else:
+ metadata_conf = built_in_metadataAlso add a debug log statement to indicate which branch was taken (dict merge vs. list concat), per the "Add logging for new flows" coding guideline for **/*.py.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@rag/svr/task_executor.py` around lines 417 - 429, metadata_conf can be a dict
that lacks a proper "properties" dict, which then falls through to the else
branch where list(metadata_conf) produces a list of keys and breaks metadata
handling; update the logic around metadata_conf/built_in_metadata to explicitly
handle three cases: (1) if metadata_conf is a dict and
metadata_conf.get("properties") is a dict -> merge properties as currently done
using turn2jsonschema(built_in_metadata), (2) if metadata_conf is a dict but
properties is missing or not a dict -> coerce into a proper object-schema by
creating a new dict with "type":"object" and "properties" equal to
turn2jsonschema(built_in_metadata).get("properties", {}) merged with any
existing metadata_conf entries (or log and preserve non-properties fields under
a safe key), and (3) if metadata_conf is an iterable/list -> keep the existing
list concat path; also add a debug-level log call indicating which branch was
taken (referencing metadata_conf, built_in_metadata, and the use of
turn2jsonschema) so flows are observable.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14383 +/- ##
=======================================
Coverage 95.30% 95.30%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 670 670
Misses 16 16
Partials 17 17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Fix confirmed – metadata parsing & deletion work perfectly Your patch works great. After rebuilding the image with your fix, files can now be parsed successfully, metadata displays correctly, and deletion also works as expected. One small note for accuracy: the original async def gen_metadata_task function in /ragflow/rag/svr/task_executor.py is located around lines 429–444 (not exactly 417--429). But the fix itself is solid. Thank you for your prompt help! |
What problem does this PR solve?
This PR fixes issue #14371 where file parsing failed after upgrading from v0.24.0 to v0.25.0, because metadata config could be a JSON Schema object but was handled like a list and later caused
KeyError: 'properties'.Type of change