Skip to content

Fix bug involving conflict between AttrJson::Model NestedAttributes and defaults - #160

Merged
jrochkind merged 2 commits into
masterfrom
fix_nested_attribute_defaults
Dec 20, 2022
Merged

Fix bug involving conflict between AttrJson::Model NestedAttributes and defaults#160
jrochkind merged 2 commits into
masterfrom
fix_nested_attribute_defaults

Conversation

@jrochkind

@jrochkind jrochkind commented Dec 20, 2022

Copy link
Copy Markdown
Owner

Ran into this bug in a real world case involving setting array default to empty array. It was very confusing and complicated, I found it too hard to reproduce the actual case in a spec, this simple spec was the best I could do for failing before the change passing after.

Only apply defaults after initialiation, with args passed in initialization, only if defaults are still needed. Previously, defaults were sometimes accidentally over-writing values set with *_attributes keys, in real world use cases.

.fill_in_defaults class method is removed -- it was never meant as public API anyhow.

This is a better way of doing defaults anyway... not sure what the comment saying that method couldn't be private was about, or why it was on class instead of instance. I think those were leftover from previous implementations, currently this is simpler anyhow.

…nd defaults

Ran into this bug in a real world case involving setting array default to empty array. It was very confusing and complicated, I found it too hard to reproduce the actual case in a spec, this simple spec was the best I could do for failing before the change passing after.

Only apply defaults after initialiation, with args passed in initialization, only if defaults are still needed. Previously, defaults were sometimes accidentally over-writing values set with `*_attributes` keys, in real world use cases.

This is a better way of doing defaults anyway... not sure what the comment saying that method couldn't be private was about, or why it was on class instead of instance. I think those were leftover from previous implementations, currently this is simpler anyhow.
@jrochkind
jrochkind merged commit f77f592 into master Dec 20, 2022
@jrochkind
jrochkind deleted the fix_nested_attribute_defaults branch December 20, 2022 22:01
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.

1 participant