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

Restore the ability to pass Active Record objects to update_all #25876

Merged
merged 1 commit into from
Jul 18, 2016

Conversation

sgrif
Copy link
Contributor

@sgrif sgrif commented Jul 18, 2016

The ability to do this was mostly unintentional, and relied on other code which
is slated to be deprecated soon. In 5.0.0 attempting to pass an Active
Record object to update_all will cast it to nil instead of grabbing
the ID. This is because we are going through Type#serialize sooner in
the stack, and not hitting the quoted_id call in the connection
adapter. This mirrors the behavior that would occur if you attempted to
assign the record to the foreign key.

While this behavior wasn't really intentional, it was a breaking change
that I didn't intend to make without deprecation. The behavior is
restored, but immediately deprecated. While this does introduce a
deprecation warning in a patch release, it deprecates behavior that was
not working in the last major, so no working code could have been
relying on it.

The implementation checks for Base explicitly instead of objects which
respond to quoted_id to avoid collisions with any other code which
overrides quoted_id. I'd like to deprecate quoted_id entirely in the
next release.

@rails-bot
Copy link

warning Warning warning

  • Pull requests are usually filed against the master branch for this repo, but this one is against 5-0-stable. Please double check that you specified the right target!

value = value.quoted_id
else
value = type_for_attribute(attr.to_s).serialize(value)
end
"#{c.quote_table_name_for_assignment(table, attr)} = #{c.quote(value)}"
Copy link
Member

Choose a reason for hiding this comment

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

Is it okay that this will c.quote(record.quoted_id)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't cause a problem with this specific case, but yeah we should probably just let the connection adapter do its thing there.

The ability to do this was mostly unintentional, and relied on other code which
is slated to be deprecated soon. In 5.0.0 attempting to pass an Active
Record object to `update_all` will cast it to `nil` instead of grabbing
the ID. This is because we are going through `Type#serialize` sooner in
the stack, and not hitting the `quoted_id` call in the connection
adapter. This mirrors the behavior that would occur if you attempted to
assign the record to the foreign key.

While this behavior wasn't really intentional, it was a breaking change
that I didn't intend to make without deprecation. The behavior is
restored, but immediately deprecated. While this does introduce a
deprecation warning in a patch release, it deprecates behavior that was
not working in the last major, so no working code could have been
relying on it.

The implementation checks for `Base` explicitly instead of objects which
respond to `quoted_id` to avoid collisions with any other code which
overrides `quoted_id`. I'd like to deprecate `quoted_id` entirely in the
next release.
@sgrif sgrif merged commit 0c30fcf into rails:5-0-stable Jul 18, 2016
@sgrif sgrif deleted the sg-update-all-ar-base branch July 18, 2016 18:51
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.

None yet

4 participants