-
Notifications
You must be signed in to change notification settings - Fork 26
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
Support ActiveRecord 7.1.x #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comments
Co-authored-by: Sorah Fukumori <[email protected]>
Co-authored-by: Sorah Fukumori <[email protected]>
Co-authored-by: Sorah Fukumori <[email protected]>
Co-authored-by: Sorah Fukumori <[email protected]>
Co-authored-by: Sorah Fukumori <[email protected]>
Co-authored-by: Sorah Fukumori <[email protected]>
Co-authored-by: Sorah Fukumori <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch & review. 👍
::Arproxy.proxy_chain.head.send :raw_execute, sql, name, **kwargs | ||
end | ||
alias_method :raw_execute_without_arproxy, :raw_execute | ||
alias_method :raw_execute, :raw_execute_with_arproxy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this break codes that directly call execute
, which might call raw_execute
internally, by invoking proxy_chain twice?
Perhaps the specs also need changes, since we only have DummyAdapter, which has independent execute
and raw_execute
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you talking about the case where both execute
and raw_execute
are defined?
I am assuming that only one of them is defined based on the version of ActiveRecord you are using.
Do you have ideas for a more approach in changing use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of the two methods should be defined in connection adapters. For example, Mysql2Adapter has both of them:
% bin/rails c
Loading development environment (Rails 7.1.4)
irb(main):001> ActiveRecord::ConnectionAdapters::Mysql2Adapter.instance_methods.include?(:execute)
=> true
irb(main):002> ActiveRecord::ConnectionAdapters::Mysql2Adapter.private_instance_methods.include?(:raw_execute)
=> true
Also ActiveRecord::ConnectionAdapters::DatabaseStatements
defines both two: https://github.com/rails/rails/blob/v7.1.4/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may be able to assume that raw_execute
must be invoked by execute
. So how about make an alias of execute
if raw_execute
is not defined?
It'd be great if we don't rely on private methods, but I'm unsure how to implement this without overriding raw_execute
.
@mirakui Do you have any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for more information.
I got to make sense of what you pointed out. 😄
I will try to change the code.
687e9ae
to
148a24d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to send pending comments...
::Arproxy.proxy_chain.head.send :raw_execute, sql, name, **kwargs | ||
end | ||
alias_method :raw_execute_without_arproxy, :raw_execute | ||
alias_method :raw_execute, :raw_execute_with_arproxy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may be able to assume that raw_execute
must be invoked by execute
. So how about make an alias of execute
if raw_execute
is not defined?
It'd be great if we don't rely on private methods, but I'm unsure how to implement this without overriding raw_execute
.
@mirakui Do you have any ideas?
cca352a
to
ceaf291
Compare
Co-authored-by: Takuma Ishikawa <[email protected]>
Co-authored-by: Takuma Ishikawa <[email protected]>
@hirocaster However, I think there are two major problems with the way this pull request is implemented, i.e., hooking First, it is not backward compatible with the proxies that Arproxy users have developed so far, and as the author of Arproxy, it is not stable enough to use without Arproxy users being sensitive to changes in the internal implementation of ActiveRecord, especially private methods such as Second, this pull request works for the mysql2 adapter, but does not work for Connection Adapters such as the Postgres Adapter by hooking For these reasons, unfortunately I cannot merge this pull request. Instead, as I suggested in #30, I have started development of a new major version, v1, for ActiveRecord 7.1 and later. Arproxy v1 will be designed to support multiple Database Adapters while maintaining backward compatibility with the previous Proxy. I hope you will be patient and look forward to the v1 release. |
@mirakui As you pointed out, I don't consider this PR to be in an ideal situation. for someone |
**I recommend waiting for the release of arproxy v1. ref: #30 **
--
Since ActiveRecord 7.1, using
#execute
no longer works as intended.ref
rails/rails@63c0d6b#diff-0b861bb8bc857373d0f0280779eb119e2937ee0edd1cc 3497292c7d14e909591
#26
Instead, I have made a change to use
#raw_execute
.Since
#raw_execute
is a private method, I'm not too keen on it, but if you have a better implementation, please give me feedback.Currently, this Patch is not in production quality, so please use it at your own risk. Also, feedback is welcome.