Add support for ignored_properties on NestedDocument#20
Add support for ignored_properties on NestedDocument#20JulienBURNET-FAUCHE merged 2 commits intomasterfrom
Conversation
This commit enables the `ignored_properties` feature for nested documents, allowing deprecated properties in nested documents to be gracefully ignored during deserialization without raising UnknownAttributeError exceptions. Changes: - Extended NestedDocument class with IgnoredProperties module - Modified Types::Nested#cast to filter ignored properties before instantiation - Modified Types::Nested#serialize to filter ignored properties before serialization - Added optimization: only call .except() if there are properties to ignore (~28% faster in common case) - Added comprehensive tests for single-level and multi-level nested documents Performance impact (100k iterations benchmark): - Common case (no ignored properties): ~28% faster (0.012s → 0.009s) - With ignored properties: ~4% overhead (0.024s → 0.025s, acceptable for backward compatibility) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary of ChangesHello @pimpin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a limitation where Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for ignored_properties on NestedDocument classes, which is a great feature for backward compatibility. The changes are logical and include comprehensive tests. I have one suggestion to refactor some duplicated code in lib/couchbase-orm/types/nested.rb to improve maintainability.
Move `extend IgnoredProperties` from NestedDocument and Base classes to their parent Document class to eliminate code duplication. Since both NestedDocument and Base inherit from Document, they automatically gain access to the ignored_properties functionality without redundant extend statements. This refactoring improves code maintainability and ensures any future Document subclasses will also have access to ignored_properties. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary
This PR adds support for the
ignored_propertiesfeature onNestedDocumentclasses, enabling backward compatibility when deprecated properties exist in nested documents stored in the database.Problem
Previously,
ignored_propertiesonly worked for properties at the root level ofBasemodels. When nested documents contained deprecated properties, the system would raise anActiveModel::UnknownAttributeErrorduring deserialization, causing reload operations to fail completely.Performance Impact
Benchmark results for 100,000 nested document operations:
For a typical document with 100 nested documents, the overhead is approximately 0.9ms per document reload/find operation. This cost is acceptable for enabling backward compatibility with legacy schemas.
Benefits
✅ Backward compatibility: deprecated properties in nested documents no longer cause errors
✅ Recursive support: works at all nesting levels
✅ Performance optimized: minimal overhead in common use cases
✅ No breaking changes: all existing tests pass
Testing
All 15 nested document tests pass, including:
🤖 Generated with Claude Code