-
Notifications
You must be signed in to change notification settings - Fork 311
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
Strange error: OCIError: ORA-01008: not all variables bound #2276
Comments
I just encountered the same problem, rails 7.0.2.3, ruby 3.10, when trying to use the deep_pluck/pluck_all gems. It was doing a query that looks like: I was able to reproduce easily with a base project from It's almost as if it fails until the schema is loaded for the table (or the schema query IS the problem, as net1957 noted), because after running something simple like |
In my case, I resolved it by replacing I imagine that Arel do correctly load the schema found some nice examples at https://martinskruze.com/does_arel_work_in_rails_7
|
I traced this problem a little deeper, and it seems like it could be considered a bug in ActiveRecord: When you call something like
This wraps the connection in a block via unprepared_statement:
And then this bit of code executes within this block:
Because the way the code is structured, the schema loading code that must run is captured inside of this "no prepared statements" block, and causes the line |
I was surprised to find that there already exists a cache busting method in the schema loading code: A fix for this (in our case) was to just add one for select_all as well:
|
We fixed it using this monkey patch: module ArelSqlPatch
def to_sql
arel # <= This is the workaround, we prebuild arel before using it in unprepared_statement
super
end
end
ActiveRecord::Relation.prepend ArelSqlPatch
|
@ioev , great find! It fixes the issue that I see. Maybe file a pull request? I actually simplified a little bit the monkey patch to avoid pasting the whole method. But in a PR of course should be done as in the original comment. module OracleEnhancedAdapterSchemaIssue2276
def column_definitions(table_name)
deleted_object_id = prepared_statements_disabled_cache.delete(object_id)
super
ensure
prepared_statements_disabled_cache.add(deleted_object_id) if deleted_object_id
end
end
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.prepend OracleEnhancedAdapterSchemaIssue2276 @davue , FYI your workaround doesn't seem to work here. |
Steps to reproduce
first request after application start or restart.
Expected behavior
After migrating the application from Rails 6.1 to 7 I get this error
Actual behavior
The application use a legacy DB, so Arel is used most time to do complex SQL queries.
If the first query after start is a query with UNION ALL, this query fail. If before that you run a simpler one, all is working as expected.
example of query (use ArelHelpers::QueryBuilder):
it fail with:
During debuging, the 'left_query.query.to_sql' generate this error and the SQL string in the error is:
and the binds Array is correctly populated.
The log contain
repeated 4 or more time.
The strangest thing:
With rubymine if I put a breakpoint on the ::Cmdmary::Etudprix.all.select(Arel.star) .... line,
If the first DB request is a more simpler SQL it also work and the fulll application is working as expected.
** the request use a connection to a shard (implemented wit a around_action block)
If i revert back to
it's working.
I don't known how to continue to try to resolve this, so I request some help about this problem.
System configuration
Rails version: rails 7.0.2.3
Oracle enhanced adapter version: 7.0.2
Ruby version: ruby 3.0.3
Oracle Database version: oracle 10.2.0.1.0, instanclient 10.2.0.1
** and arel-helpers (2.14.0), composite_primary_keys (14.0.4)
The text was updated successfully, but these errors were encountered: