fix: use dict spread to avoid shallow copy mutation in index_data_points#2530
fix: use dict spread to avoid shallow copy mutation in index_data_points#2530nightcityblade wants to merge 1 commit intotopoteretes:devfrom
Conversation
Replace direct mutation of shared metadata dict with a new dict via spread operator. This prevents the for-loop from being truncated when iterating over multiple index_fields, as the original data_point.metadata is no longer mutated by copies. Fixes topoteretes#2529
Please make sure all the checkboxes are checked:
|
|
Hello @nightcityblade, thank you for submitting a PR! We will respond as soon as possible. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughFixed a shallow copy metadata mutation bug in the index data points task. Replaced direct field assignment with dictionary unpacking to ensure each indexed data point receives a proper copy of metadata while maintaining only the relevant index field. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsTimed out fetching pipeline failures after 30000ms 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 |
dexters1
left a comment
There was a problem hiding this comment.
PR is made towards wrong branch. Check CONTRIBUTING.md
https://github.com/topoteretes/cognee/blob/main/CONTRIBUTING.md
|
Thanks @dexters1! Updated the base branch to |
|
Thanks for the feedback! The PR currently targets |
Description
When a
DataPointhas multipleindex_fields, theforloop inindex_data_points()only processes the first field. This happens becausemodel_copy()performs a shallow copy, soindexed_data_point.metadataanddata_point.metadatareference the same dict. Settingindexed_data_point.metadata["index_fields"] = [field_name]mutates the original, truncating the iteration list.The fix replaces the direct dict mutation with a dict spread (
{**data_point.metadata, "index_fields": [field_name]}), creating a new dict for each copy so the original is never modified.Acceptance Criteria
index_fieldsare all processed and embedded correctlydata_point.metadata["index_fields"]is not mutated during iterationType of Change
Screenshots
N/A — single-line logic fix verified via manual simulation.
Pre-submission Checklist
DCO Affirmation
I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin.
Fixes #2529
Summary by CodeRabbit