fix(lfx): preserve document metadata during conversion - #14677
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. Walkthrough
ChangesDocument conversion
Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: ⚪ Minimal · up to This change prevents document metadata from being mutated during conversion while preserving the converted output; no actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 8 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (8 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Summary
Document's metadata before adding its page content to the convertedDataobject.textvalue on the source document.Problem
Data.from_document()assigneddocument.metadatadirectly to a local variable and then wrote the page content into itstextkey. That write mutated the inputDocument, overwriting an existing metadata value or adding a new key as a side effect. Callers that reuse the original document after conversion therefore observe changed metadata.The reverse conversion already copies
Data.databefore removing its text field. This change applies the same non-mutating boundary tofrom_document(). The convertedDataoutput is unchanged; only the source document is preserved.A shallow copy is sufficient because the conversion only writes one top-level key.
Validation
document.metadata["text"]changes from"Metadata text"to"Doc content".uv run --isolated --package lfx pytest src/lfx/tests/unit/test_data_class.py src/lfx/tests/unit/schema src/lfx/tests/unit/helpers -q— 392 passed, 1 skipped.uv run --isolated --package lfx lfx --helpcompletes successfully.Summary by CodeRabbit