Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Configuration Inheritance Fix #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

feat: Configuration Inheritance Fix #56

wants to merge 1 commit into from

Conversation

seuros
Copy link
Member

@seuros seuros commented Mar 3, 2025

Problem

There's an issue with inheritance in Trailblazer Finder where modifying configuration (specifically paging settings) in one subclass affects other subclasses if they are defined later. This happens because the clone method in the Configuration class only performs a shallow copy of nested data structures, causing different subclasses to share references to the same configuration objects.

Diagram

classDiagram
    class Configuration {
        +entity
        +paging
        +properties
        +sorting
        +filters
        +adapter
        +paginator
        +clone()
        -deep_copy(obj)
    }
    
    class ParentFinder {
        +config
        +paging(per_page: 10)
    }
    
    class ChildFinderA {
        +config
        +paging(per_page: 30)
    }
    
    class ChildFinderB {
        +config
        # Should remain per_page: 10
    }
    
    ParentFinder <|-- ChildFinderA : inherits
    ParentFinder <|-- ChildFinderB : inherits
    ParentFinder --> Configuration : uses
    ChildFinderA --> Configuration : uses
    ChildFinderB --> Configuration : uses
Loading

@seuros seuros requested a review from apotonick March 3, 2025 19:41
result[key] = value.is_a?(Hash) ? deep_copy(value) : value
end
result
end
end

module Dsl
Copy link
Member

Choose a reason for hiding this comment

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

We do have an inheritance mechanism in trailblazer-declarative, it's used in all other gems 😬

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