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

Handle false in relation strict loading checks #41688

Merged
merged 1 commit into from
Mar 16, 2021

Conversation

eileencodes
Copy link
Member

Fixes: #41453
Closes: #41461

Previously when a model had strict loading set to true and then had a
relation set strict_loading to false the false wasn't considered when
deciding whether to raise/warn about strict loading.

Code example:

class Dog < ActiveRecord::Base
  self.strict_loading_by_default = true

  has_many :treats, strict_loading: false
end

In the example, dog.treats would still raise even though
strict_loading was set to false. This is a bug effecting more than
Active Storage which is why I made this PR superceeding #41461. We need
to fix this for all applications since the behavior is a little
surprising. I took the test from ##41461 and the code suggestion from #41453
with some additions.

Co-authored-by: Radamés Roriz radamesroriz@gmail.com

Fixes: rails#41453
Closes: rails#41461

Previously when a model had strict loading set to true and then had a
relation set strict_loading to false the false wasn't considered when
deciding whether to raise/warn about strict loading.

Code example:

```ruby
class Dog < ActiveRecord::Base
  self.strict_loading_by_default = true

  has_many :treats, strict_loading: false
end
```

In the example, `dog.treats` would still raise even though
`strict_loading` was set to false. This is a bug effecting more than
Active Storage which is why I made this PR superceeding rails#41461. We need
to fix this for all applications since the behavior is a little
surprising. I took the test from #rails#41461 and the code suggestion from rails#41453
with some additions.

Co-authored-by: Radamés Roriz <radamesroriz@gmail.com>
@eileencodes eileencodes merged commit 6655c78 into rails:main Mar 16, 2021
@eileencodes eileencodes deleted the handle-false-for-strict-loading branch March 16, 2021 21:09
eileencodes added a commit that referenced this pull request Mar 17, 2021
…ading

Handle false in relation strict loading checks
@eileencodes
Copy link
Member Author

I also backported this to 6-1-stable in 6464f2f

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.

Strict loading opt-out for each reflection
1 participant