-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
reverse_sql_order fails to reverse reversible order #44719
Comments
Thanks for the report, are you able to confirm if this is an issue on rails 7 too? |
Yes. Same error with |
You're right that the split is due to functions with arguments, see #25987 / #18928 (comment) I suppose you could add a check to see if the comma is immediately preceded by an |
Agreed, I don't think it's worth fixing especially since you can use Arel to achieve the same result without a problem. I created the issue because I was looking for an explanation or workaround and couldn't find any information on it, when searching for the method name or error. Figured it might help someone in the future. |
Thanks for creating it! I will close since no action's required, but it should still be findable via google / the issues search here. |
The way
ActiveRecord::QueryMethods#reverse_sql_order
andActiveRecord::QueryMethods#does_not_support_reverse?
test for reversibility/perform it, breaks in cases likebecause they split on the comma in
IN (0, 2)
. Presumably, that split is intended to check for function calls or something.Ordering by
CASE
works when built via Arel, which I think is the proper way to do it anyway. I just wasn't aware Arel could do this when I first wrote the code that triggered the bug.I figured I'd raise an issue in case someone else was googling around due to this bug.
Not sure what a good way to fix this would be, probably not worth fixing and adding more complexity to
reverse_sql_order
, tbh.Steps to reproduce
Expected behavior
All the asserts should pass.
Actual behavior
The last assert triggers
IrreversibleOrderError
System configuration
Rails version: Checked on 5.2/6.1.5/7.0
Ruby version: 2.5.1/2.7
The text was updated successfully, but these errors were encountered: