Repository navigation
Make AR::Attributes independent of AR::ModelSchema - #38871
jonathanhefner wants to merge 8 commits into
Conversation
45e4ffe to
f509c0e
Compare
f509c0e to
1bfb1a4
Compare
|
@casperisfine Would this PR be of any interest to you? I noticed you had some issues with Also, I know you've done several optimizations to improve application boot performance. I'm curious if removing the |
Well, the issue I had is that there are several things during attribute definition that requires to access The main one being TBH I'm having a bit of a hard time to understand this PR (not your fault), so it's hard for me to say wether it goes in what I think is the good direction or not. But I'll continue exploring it.
So while trying to answer this, I realized my benchmark had a blindspot (because of the connection problem explained above). I'll be fixing it and will come back to you once I have more accurate benchmarks. |
Ok, so I'm afraid I'll have to give up for now on that one. I've been fighting with AR for the last 3 hours and defining attributes without connecting to the DB is terribly hard, even with ugly monkey patches. |
1bfb1a4 to
88c6a92
Compare
Thank you for your feedback! I realized I needed to do a better job of explaining this PR. I hope I've done that now, but I would be appreciative of further critique.
I can't say for sure if this PR will help, because I haven't had to face those problems, but here's what happens now (in this PR):
|
I see. That's indeed is a bit cleaner than the way we unload on error currently. But that doesn't really solve the root cause IMO (doesn't mean this isn't worth it, I just can't say). |
This is a common `class_attribute` implementation issue (e.g. rails#39467, rails#39468, rails#38871). For now, we should take care of the change propagation by themselves if we want to ensure the propagation after the `class_attribute` are accessed in subclasses. Fixes rails#20678.
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
734c664 to
9430583
Compare
This is an alternate take on rails#39882, based on top of rails#38871. Co-authored-by: Ryuta Kamizono <[email protected]>
9430583 to
acb539d
Compare
`AttributeDecorators` was removed in rails#39882 in favor of calling the `attribute` macro with a block. However, this technique overwrote the original attribute type, which is still needed by some decorators. Thus those decorators had to bypass the encapsulation of the `Attributes` module to retrieve the original attribute type. This commit makes the `attribute` macro retain the original attribute type when a new type is not specified.
This refactor is a step towards porting more modules from Active Record to Active Model. ActiveRecord::Attributes now no longer depends on ActiveRecord::ModelSchema.
acb539d to
e035a9e
Compare
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
This refactor is a step towards porting more modules from Active Record to Active Model.
ActiveRecord::Attributesno longer depends onActiveRecord::ModelSchema. Likewise,ActiveRecord::AttributeDecoratorsno longer depends onActiveRecord::ModelSchema, and now depends onActiveRecord::Attributesinstead.An overview of the changes:
_default_attributesandattribute_typesfromModelSchematoAttributes.ModelSchema::reload_schema_from_cachewithAttributes::reset_attributes.Attributes::define_attributewith calls toAttributes::add_attribute_to_attribute_set, which does not mutate global state. (The original method was not removed because it is publicly documented.)ModelSchema::load_schema!withAttributes::add_deferred_to_attribute_set, which does not mutate global state.Attributes::_default_attributesas the point of entry forAttributes::add_deferred_to_attribute_set, and ensure neither are part of a circular call tree.MonitorfromModelSchema::load_schema, which now only callsAttributes::_default_attributes, which itself only writes one piece of global state, atomically.ModelSchema::load_schema.Coincidentally, fixes #38293.