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

Fix primary_abstract_class in lazy loaded envs #42239

Conversation

eileencodes
Copy link
Member

If you have an application that has ApplicationRecord and another
class like PrimaryApplicationRecord and the PrimaryApplicationRecord
is set to primary_abstract_class, then in a lazy loaded env like
development, it's possible for application_record_class to be set to
ApplicationRecord. This would then raise an error that you can't reset
the class if you then loaded PrimaryApplicationRecord.

To fix this we've removed the setter for application_record_class in
the fall through so that if this does happen, ApplicationRecord will
only be the primary class until the correct primary class is loaded.
If an application sets 2 classes to primary_abstract_class, the error
will still be raised.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com

If you have an application that has `ApplicationRecord` and another
class like `PrimaryApplicationRecord` and the `PrimaryApplicationRecord`
is set to `primary_abstract_class`, then in a lazy loaded env like
development, it's possible for `application_record_class` to be set to
`ApplicationRecord`. This would then raise an error that you can't reset
the class if you then loaded `PrimaryApplicationRecord`.

To fix this we've removed the setter for `application_record_class` in
the fall through so that if this does happen, `ApplicationRecord` will
only be the primary class until the correct primary class is loaded.
If an application sets 2 classes to `primary_abstract_class`, the error
will still be raised.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com
@eileencodes eileencodes merged commit 5ddff2b into rails:main May 17, 2021
@eileencodes eileencodes deleted the fix-primary-abstract-class-in-lazy-loaded-env branch May 17, 2021 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant