Fix custom predicate formatter generating extra quotes in SQL #1636
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.
Fixes an issue where custom predicates with formatters that return comma-separated string values generate malformed SQL with extra quotes.
Problem
When using custom predicates with formatters that transform input into comma-separated strings, the generated SQL contains extra quotes that break the syntax:
Expected SQL:
Actual SQL (broken):
Root Cause
The issue was in the
formatted_values_for_attribute
method inlib/ransack/nodes/condition.rb
. When a formatter returns a string like"test','othertest"
, it was being treated as a single value instead of being parsed into separate array elements for IN clauses.Solution
Modified
formatted_values_for_attribute
to detect when:wants_array
is true for 'in'/'not_in' predicates)"','"
In these cases, the string is split back into individual array elements using
split("','")
.Changes
Backward Compatibility
This change maintains full backward compatibility:
The fix only applies to the specific case of IN/NOT IN predicates with formatters that return comma-separated strings, making it a surgical fix that doesn't impact other functionality.
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.