Fix update_all to correctly handle Arel nodes#22
Merged
a5-stable merged 1 commit intokufu:featuresfrom Feb 19, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
update_allto correctly handle updates containing Arel nodes.Background
The current
update_allimplementation serializes update values usingsanitize_sql_for_assignment.However, this method cannot convert Arel nodes (e.g.,
Arel::Nodes::Addition) to SQL, causing runtime errors in the following cases:increment!/decrement!(internally generates Arel expressions likecolumn + 1)counter_culturegem (uses Arel expressions for counter updates)This issue has also been reported in the upstream repository (citusdata#282).
Changes
Aligned with Rails' own
update_allimplementation by using_substitute_valuesfor Hash updates._substitute_valuesto preserve Arel nodes as-is and convert other values to bind parameterssanitize_sql_for_assignmentas beforelock_versionauto-increment behavior as RailsReference: Rails implementation
https://github.com/rails/rails/blob/8-1-stable/activerecord/lib/active_record/relation.rb#L615-L625
Note
Due to the use of
_substitute_values, the generated SQL now uses bind parameters ($1,$2...) instead of literal values.Existing SQL string comparison tests have been adjusted accordingly.