Skip to content

Fix metadata parsing regression for upgraded v0.24 datasets - #14383

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
6ba3i:fix/metadata_regression
Apr 27, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
6ba3i:fix/metadata_regression

Conversation

@6ba3i

@6ba3i 6ba3i commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

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

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

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Apr 27, 2026
@coderabbitai

coderabbitai Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7750694e-a03c-49bf-a0e9-d73e9a656609

📥 Commits

Reviewing files that changed from the base of the PR and between ef599a6 and f1f6997.

📒 Files selected for processing (1)
  • rag/svr/task_executor.py

📝 Walkthrough

Walkthrough

gen_metadata_task in doc_question_proposal now builds metadata_conf schema-aware: it merges generated built_in_metadata into an existing dict schema's properties, or concatenates when original is a list, or falls back to built_in_metadata for other types. metadata_conf is used for cache key and schema generation.

Changes

Cohort / File(s) Summary
Metadata Schema Merging
rag/svr/task_executor.py
Reworked gen_metadata_task to treat parser_config["metadata"] as either a dict JSON Schema (ensure/merge properties with built_in_metadata), a list (concatenate with built_in_metadata), or otherwise replace with built_in_metadata. Uses resulting metadata_conf for cache key and schema generation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Suggested labels

size:XS

Poem

🐰 I sniffed the schema, found a hole in the night,
I stitched up properties and made it right,
Whether dict or list, I hopped in to mend,
Cache and schema now march hand in hand. 🥕✨

🚥 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 and specifically describes the main change: fixing a metadata parsing regression affecting datasets upgraded from v0.24.
Description check ✅ Passed The description includes both required sections from the template: problem statement with issue reference and type of change marked as Bug Fix.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

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

@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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6a23dfe and ef599a6.

📒 Files selected for processing (1)
  • rag/svr/task_executor.py

Comment thread rag/svr/task_executor.py Outdated
Comment on lines +417 to +429
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

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.

⚠️ Potential issue | 🟡 Minor

🧩 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 -40

Repository: 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.py

Repository: 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 -60

Repository: infiniflow/ragflow

Length of output: 4296


🏁 Script executed:

# Get complete turn2jsonschema function
sed -n '328,365p' common/metadata_utils.py

Repository: 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 -A10

Repository: 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 -A30

Repository: 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_metadata

Also 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.

@6ba3i 6ba3i added the ci Continue Integration label Apr 27, 2026
@6ba3i
6ba3i marked this pull request as draft April 27, 2026 05:23
@6ba3i
6ba3i marked this pull request as ready for review April 27, 2026 05:23
@codecov

codecov Bot commented Apr 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.30%. Comparing base (4dcc42e) to head (f1f6997).
⚠️ Report is 12 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit 4303be2 into infiniflow:main Apr 27, 2026
2 checks passed
@LijiaTong

Copy link
Copy Markdown

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!

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:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants