Regression in 5.2.0: unscoped
with a block no longer behaves the same as unscoped
#33387
Labels
Milestone
unscoped
with a block no longer behaves the same as unscoped
#33387
While working on upgrading from Rails 5.1 -> Rails 5.2 we found an issue where the behavior of
unscoped
changed when used with a block. The PR that changed behavior is #29301Essentially what is happening is when
unscoped { all }
used to have the behavior ofOrganization.where(id: org.id).unscoped { Organization.all }
but now has the behavior ofOrganizatio.where(id: org.id).unscoped { Organization.where(id: org.id).all }
- where the scope is re-applied inside the block.The new behavior kind of makes sense to me but I think it's a surprising change with strange side effects. We wouldn't have found this if we hadn't been explicitly testing the sql in our application.
cc/ @kamipo @matthewd @rafaelfranca for the original pr
cc/ @jhawthorn @tenderlove for GitHub visibility
Steps to reproduce
Expected behavior
The scope should not be re-applied inside the
unscoped
block.unscoped { all }
should behave the same asunscoped.all
.Actual behavior
When using unscoped with a block the outside scope is re-applied inside the scope.
System configuration
Rails version: 5.2.0, master
Ruby version: 2.5.0
The text was updated successfully, but these errors were encountered: