-
Notifications
You must be signed in to change notification settings - Fork 315
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
Oracle12 visitor - Combination of limit and lock is not supported #2237
Comments
Seems to be related also to #1070 |
@yahonda Can we get a little clarification on this lock subject. Most of the discussions on it are pretty old, and I can't seem to come up with a definitive approach to get row locking to work. Most of my errors are Doesn't matter, if I find_by_id, where(id: ) etc etc. Is with_lock just not supported? A little guidance would help. I can volunteer to put in a patch if I know what's the latest state on this and what's the history behind it. AJ |
One possible approach is using a query without limits. Assuming you're using where on a unique value it shouldn't really make a difference in amount of objects returned (and if you're not doing it on a unique value then the setting a limit of 1 is not going to reliably work anyway).
|
@joerixaop , thank you for the suggested workaround. It seems possible to workaround this under the hood like (on Rails 6.1.x): ActiveRecord::Relation.prepend(Module.new do
def find_one(id)
if ActiveRecord::Base === id
raise ArgumentError, <<-MSG.squish
You are passing an instance of ActiveRecord::Base to `find`.
Please pass the id of the object by calling `.id`.
MSG
end
relation = where(primary_key => id)
record = relation.to_a.first # this is the only change from the original method
raise_record_not_found_exception!(id, 0, 1) unless record
record
end
end) I think it is alright to patch all FYI my original workaround to use But since I don't expect anybody to be using an old oracle version anymore, I don't see much sense to file a separate bug about it. Much better would be to fix the new visitor somehow. |
Oracle12
Arel visitor does not handle sub-queries withLIMIT
properly and this makes locking a row impossible. While it works in normal queries, in sub-queries that doesn't seem to be the case.Steps to reproduce
Expected behavior
Actual behavior
Possible workaround - use
Arel::Visitors::Oracle
Arel::Visitors::Oracle
works fine though because it always translatesLIMIT
statements toROWNUM
.The example above properly works, if we add to
application.rb
:System configuration
Oracle Enhanced Adapter version
7.0.0
Rails version:
Rails 7.0.1
Ruby version:
ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-linux]
Oracle version:
19.3.0
The text was updated successfully, but these errors were encountered: