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 Relation#transaction to not apply a default scope #50395

Merged
merged 1 commit into from
Dec 19, 2023

Conversation

casperisfine
Copy link
Contributor

Fix: #50368

When called on a scope it would go through the default scoping delegator that applies a default scope, which make no sense.

Fix: rails#50368

When called on a scope it would go through the default scoping
delegator that applies a default scope, which make no sense.
casperisfine pushed a commit to Shopify/rails that referenced this pull request Dec 19, 2023
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allowed calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a current scope setter.

So I think we should be more strict about it.
@byroot byroot merged commit 18b8f37 into rails:main Dec 19, 2023
4 checks passed
byroot added a commit that referenced this pull request Dec 19, 2023
Fix `Relation#transaction` to not apply a default scope
byroot added a commit that referenced this pull request Dec 19, 2023
Fix `Relation#transaction` to not apply a default scope
@byroot
Copy link
Member

byroot commented Dec 19, 2023

Backported to 7-0-stable and 7-1-stable.

casperisfine pushed a commit to Shopify/rails that referenced this pull request Dec 19, 2023
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allowed calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a current scope setter.

So I think we should be more strict about it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request Dec 22, 2023
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allowed calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a current scope setter.

So I think we should be more strict about it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request Jan 15, 2024
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allowed calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a current scope setter.

So I think we should be more strict about it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 10, 2024
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allowed calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a current scope setter.

So I think we should be more strict about it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 10, 2024
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allowed calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a current scope setter.

So I think we should be more strict about it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 10, 2024
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allowed calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a current scope setter.

So I think we should be more strict about it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 10, 2024
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allowed calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a current scope setter.

So I think we should be more strict about it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 13, 2024
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allowed calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a current scope setter.

So I think we should be more strict about it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 13, 2024
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allowed calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a current scope setter.

So I think we should be more strict about it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 13, 2024
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allowed calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a current scope setter.

So I think we should be more strict about it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 13, 2024
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allowed calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a current scope setter.

So I think we should be more strict about it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 13, 2024
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allowed calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a current scope setter.

So I think we should be more strict about it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 28, 2024
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allows calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a global scope setter.

This also has led to bugs in the past, like rails#51776

So I think we should be more strict about it.

We can't deprecate this behavior because gems might depend on it, however we
can ban it from Active Record's own test suite to avoid regressions.
xjunior pushed a commit to xjunior/rails that referenced this pull request Jun 9, 2024
In rails#50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allows calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a global scope setter.

This also has led to bugs in the past, like rails#51776

So I think we should be more strict about it.

We can't deprecate this behavior because gems might depend on it, however we
can ban it from Active Record's own test suite to avoid regressions.
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 7.1 regression in model scoping in callback when created from association
2 participants