-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Safe-autocorrect with Rails/WhereRange does not work correctly when #1283
Comments
Are you on MySQL? Because for PostgreSQL, the original query produces an "ambiguous column" error. |
@fatkodima I'm on PostgreSQL. Apologies if my attempt to extract the details from our code base has mislead you. I agree that it should be marked as unsafe. |
So are you sure that |
@fatkodima apologies, I suspect my write up was not clear enough. There is no end_at column on the Bookings table
|
So this issue should be closed? |
No I'm not saying that. I'm trying to clarify the situation. The application has Bookings, which does not have an end_at column, and Events which does have end_at. The Vehicle model has many bookings and has a method called In app/models/vehicle.rb
In app/models/booking.rb
With that in mind when the cop is run in safe method it modifies the
Which is incorrect, and when it is referenced it fails:
Whereas when over_due is modified to be
Then it works and returns the bookings records
|
Got it, thanks. |
[Fix #1283] Mark `WhereRange` as unsafe autocorrect
rubocop -a does not correctly update this method with the Rails/WhereRange cop
In app/models/booking.rb
It's referenced and used in app/models/vehicle.rb
Expected behavior
The expected corrected code is
Converted to SQL this gives
The where clause is based on
events.end_at
Either the safe-autocorrect needs to detect and cope with this situation or this needs to be handled as an unsafe-autocorrection, ideally with documentation that explains the scenario(s) where it isn't safe.
The issue with this is that the where clause attempts to reference the
end_at
attribute on the Booking model rather than the Event model.Actual behavior
This is the save auto-corrected method
Converted to SQL this gives
The where clause is based on
bookings.end_at
Steps to reproduce the problem
RuboCop version
The text was updated successfully, but these errors were encountered: