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

Raise StrictLoadingViolationError with polymorphic relation violations #45016

Conversation

adrianna-chang-shopify
Copy link
Contributor

Summary

Closes: #44906

Performing strict_loading! on a model with a polymorphic association currently raises an ArgumentError because it attempts to look up the klass for the association, which is not possible. The error message for StrictLoadingViolationError on models with polymorphic relationships should omit the klass for the association.

Copy link
Member

@eileencodes eileencodes left a comment

Choose a reason for hiding this comment

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

I realized while reviewing this activerecord/lib/active_record/log_subscriber.rb needs to be updated too since it also defines a warning message and calls klass on the payload. The same message can be used for both.

@adrianna-chang-shopify
Copy link
Contributor Author

That was an oversight on my part, thanks @eileencodes ! ❤️

Performing strict_loading! on a model with a polymorphic association
currently raises an ArgumentError because it attempts to look up the
klass on the polymorphic association, which is not possible. The error
message for StrictLoadingViolationError on models with polymorphic
relationships should omit the klass for the association.
@adrianna-chang-shopify adrianna-chang-shopify force-pushed the ac-fix-strict-loading-polymorphic-associations branch from 66c038d to 71828a4 Compare May 5, 2022 15:03
@eileencodes eileencodes merged commit cd2949d into rails:main May 5, 2022
eileencodes added a commit that referenced this pull request May 5, 2022
…oading-polymorphic-associations

Raise StrictLoadingViolationError with polymorphic relation violations
@eileencodes
Copy link
Member

Backported to 7-0-stable in cd7700b

@adrianna-chang-shopify adrianna-chang-shopify deleted the ac-fix-strict-loading-polymorphic-associations branch May 5, 2022 15:34
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.

ActiveRecord::StrictLoadingViolationError is not raised when loading polymorphic relations.
2 participants