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 .with_connection to not set current scope #51776

Merged
merged 1 commit into from May 10, 2024

Conversation

casperisfine
Copy link
Contributor

Fix: #51775

This us us being bitten by #50396 once more. We should really make this delegation much stricter.

cc @ghiculescu

@ghiculescu sorry for not adding a test but I got some travel coming up, feel free to add one in a PR and I'll merge it.

Also I really need to finish #50396

Fix: rails#51775

This us us being bitten by rails#50396
once more. We should really make this delegation much stricter.
@byroot byroot merged commit f8537e9 into rails:main May 10, 2024
3 of 4 checks passed
@ghiculescu
Copy link
Member

Thanks @byroot 😍

@joshuay03 FYI 👍

casperisfine pushed a commit to Shopify/rails that referenced this pull request May 13, 2024
Ref: rails#50396
Ref: rails#51776

`ActiveRecord::Relation` automatically delegates missing methods
to the model class wrapped in a `scoping { }` block.

This is to support scoping in user defined class methods. The problem
however is that it's very error prone for the framework, because we
can mistakenly call model methods from inside `Relation` and not
realized we're applying a global scope.

In the best case scenario it's just a waste of performance, but
it can also lead to bugs like rails#51775

I'm planning to restrict this automatic delegation to methods defined
in childs of `ActiveRecord::Base` only: rails#50396
but for this to work we must first refactor any Rails code that rely on it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 13, 2024
Ref: rails#50396
Ref: rails#51776

`ActiveRecord::Relation` automatically delegates missing methods
to the model class wrapped in a `scoping { }` block.

This is to support scoping in user defined class methods. The problem
however is that it's very error prone for the framework, because we
can mistakenly call model methods from inside `Relation` and not
realized we're applying a global scope.

In the best case scenario it's just a waste of performance, but
it can also lead to bugs like rails#51775

I'm planning to restrict this automatic delegation to methods defined
in childs of `ActiveRecord::Base` only: rails#50396
but for this to work we must first refactor any Rails code that rely on it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 13, 2024
Ref: rails#50396
Ref: rails#51776

`ActiveRecord::Relation` automatically delegates missing methods
to the model class wrapped in a `scoping { }` block.

This is to support scoping in user defined class methods. The problem
however is that it's very error prone for the framework, because we
can mistakenly call model methods from inside `Relation` and not
realized we're applying a global scope.

In the best case scenario it's just a waste of performance, but
it can also lead to bugs like rails#51775

I'm planning to restrict this automatic delegation to methods defined
in childs of `ActiveRecord::Base` only: rails#50396
but for this to work we must first refactor any Rails code that rely on it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 13, 2024
Ref: rails#50396
Ref: rails#51776

`ActiveRecord::Relation` automatically delegates missing methods
to the model class wrapped in a `scoping { }` block.

This is to support scoping in user defined class methods. The problem
however is that it's very error prone for the framework, because we
can mistakenly call model methods from inside `Relation` and not
realized we're applying a global scope.

In the best case scenario it's just a waste of performance, but
it can also lead to bugs like rails#51775

I'm planning to restrict this automatic delegation to methods defined
in childs of `ActiveRecord::Base` only: rails#50396
but for this to work we must first refactor any Rails code that rely on it.
casperisfine pushed a commit to Shopify/rails that referenced this pull request May 13, 2024
Ref: rails#50396
Ref: rails#51776

`ActiveRecord::Relation` automatically delegates missing methods
to the model class wrapped in a `scoping { }` block.

This is to support scoping in user defined class methods. The problem
however is that it's very error prone for the framework, because we
can mistakenly call model methods from inside `Relation` and not
realized we're applying a global scope.

In the best case scenario it's just a waste of performance, but
it can also lead to bugs like rails#51775

I'm planning to restrict this automatic delegation to methods defined
in childs of `ActiveRecord::Base` only: rails#50396
but for this to work we must first refactor any Rails code that rely on it.
fractaledmind pushed a commit to fractaledmind/rails that referenced this pull request May 13, 2024
Ref: rails#50396
Ref: rails#51776

`ActiveRecord::Relation` automatically delegates missing methods
to the model class wrapped in a `scoping { }` block.

This is to support scoping in user defined class methods. The problem
however is that it's very error prone for the framework, because we
can mistakenly call model methods from inside `Relation` and not
realized we're applying a global scope.

In the best case scenario it's just a waste of performance, but
it can also lead to bugs like rails#51775

I'm planning to restrict this automatic delegation to methods defined
in childs of `ActiveRecord::Base` only: rails#50396
but for this to work we must first refactor any Rails code that rely on it.
fractaledmind pushed a commit to fractaledmind/rails that referenced this pull request May 13, 2024
Ref: rails#50396
Ref: rails#51776

`ActiveRecord::Relation` automatically delegates missing methods
to the model class wrapped in a `scoping { }` block.

This is to support scoping in user defined class methods. The problem
however is that it's very error prone for the framework, because we
can mistakenly call model methods from inside `Relation` and not
realized we're applying a global scope.

In the best case scenario it's just a waste of performance, but
it can also lead to bugs like rails#51775

I'm planning to restrict this automatic delegation to methods defined
in childs of `ActiveRecord::Base` only: rails#50396
but for this to work we must first refactor any Rails code that rely on it.
dhh pushed a commit that referenced this pull request May 14, 2024
Ref: #50396
Ref: #51776

`ActiveRecord::Relation` automatically delegates missing methods
to the model class wrapped in a `scoping { }` block.

This is to support scoping in user defined class methods. The problem
however is that it's very error prone for the framework, because we
can mistakenly call model methods from inside `Relation` and not
realized we're applying a global scope.

In the best case scenario it's just a waste of performance, but
it can also lead to bugs like #51775

I'm planning to restrict this automatic delegation to methods defined
in childs of `ActiveRecord::Base` only: #50396
but for this to work we must first refactor any Rails code that rely on it.
dhh pushed a commit that referenced this pull request May 14, 2024
Ref: #50396
Ref: #51776

`ActiveRecord::Relation` automatically delegates missing methods
to the model class wrapped in a `scoping { }` block.

This is to support scoping in user defined class methods. The problem
however is that it's very error prone for the framework, because we
can mistakenly call model methods from inside `Relation` and not
realized we're applying a global scope.

In the best case scenario it's just a waste of performance, but
it can also lead to bugs like #51775

I'm planning to restrict this automatic delegation to methods defined
in childs of `ActiveRecord::Base` only: #50396
but for this to work we must first refactor any Rails code that rely on it.
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.

scope_attributes leaks into Active Record life cycle callbacks since PR #51725
3 participants