Skip to content

Add support for ignored_properties on NestedDocument#20

Merged
JulienBURNET-FAUCHE merged 2 commits intomasterfrom
handle_ignored_properties_on_nested_doc
Oct 28, 2025
Merged

Add support for ignored_properties on NestedDocument#20
JulienBURNET-FAUCHE merged 2 commits intomasterfrom
handle_ignored_properties_on_nested_doc

Conversation

@pimpin
Copy link
Collaborator

@pimpin pimpin commented Oct 27, 2025

Summary

This PR adds support for the ignored_properties feature on NestedDocument classes, enabling backward compatibility when deprecated properties exist in nested documents stored in the database.

Problem

Previously, ignored_properties only worked for properties at the root level of Base models. When nested documents contained deprecated properties, the system would raise an ActiveModel::UnknownAttributeError during deserialization, causing reload operations to fail completely.

Performance Impact

Benchmark results for 100,000 nested document operations:

Scenario Time
No ignored properties 0.009s
With ignored properties 0.025s

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:

  • Basic ignored properties filtering
  • Multi-level nested documents with ignored properties at different levels
  • Existing functionality remains unchanged

🤖 Generated with Claude Code

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>
@gemini-code-assist
Copy link

Summary of Changes

Hello @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 ignored_properties only applied to root-level Base models, causing ActiveModel::UnknownAttributeError when nested documents contained deprecated fields. By extending this functionality to NestedDocument classes, the system can now gracefully handle and ignore such properties during deserialization and serialization, ensuring data integrity and preventing failures during reload operations. The changes are also optimized for performance, particularly when no properties need to be ignored.

Highlights

  • NestedDocument Ignored Properties: The NestedDocument class now supports the ignored_properties feature, enabling backward compatibility for deprecated fields within nested structures.
  • Deserialization and Serialization Filtering: The Types::Nested#cast and Types::Nested#serialize methods have been updated to filter out ignored properties from hash values before instantiating or serializing nested documents.
  • Performance Optimization: An optimization was added to skip the filtering logic when no properties are marked as ignored, resulting in approximately a 28% performance improvement in the common case.
  • Comprehensive Testing: New tests have been introduced to cover single and multi-level nested documents, ensuring the ignored_properties functionality works as expected across different nesting depths.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@JulienBURNET-FAUCHE JulienBURNET-FAUCHE merged commit c48ab14 into master Oct 28, 2025
19 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants