Skip to content
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

Fix on Ruby 3 #283

Merged
merged 3 commits into from
Jan 19, 2021
Merged

Fix on Ruby 3 #283

merged 3 commits into from
Jan 19, 2021

Conversation

mlarraz
Copy link
Member

@mlarraz mlarraz commented Jan 14, 2021

Because of how much method delegation and metaprogramming this gem uses, there were a number of issues due to the Ruby 3 keyword argument change.

Most are resolvable by adding ruby2_keywords, but the stuff using instance_eval is a bit more involved.

@mlarraz mlarraz force-pushed the ruby_3_support branch 8 times, most recently from 4827e64 to 253a6b8 Compare January 14, 2021 22:15
@mlarraz mlarraz force-pushed the ruby_3_support branch 21 times, most recently from 2407938 to a20386d Compare January 15, 2021 21:57
@mlarraz mlarraz force-pushed the ruby_3_support branch 11 times, most recently from ecdb1fc to c8ec6f5 Compare January 16, 2021 05:07

# Each method the Makara::Proxy needs to hijack should be redefined in the underlying connection.
# The new definition should allow for the proxy to intercept the invocation if required.
@proxy.class.hijack_methods.each do |meth|
extension << %Q{
def #{meth}(*args, &block)
method_call = RUBY_VERSION >= "3.0.0" ? "public_send(#{meth.inspect}, ...)" : "#{meth}(*args, &block)"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need public_send here because foo.bar=(...) is not valid syntax in Ruby 3.0 (even though foo.bar(...) is)

@mlarraz mlarraz marked this pull request as ready for review January 19, 2021 19:19
@@ -73,7 +73,13 @@
Test::User.exists? # flush other (schema) things that need to happen

con = connection.replica_pool.connections.first
expect(con).to receive(:exec_query).with(/SELECT\s+1\s*(AS one)?\s+FROM .?users.?\s+LIMIT\s+.?1/, any_args).once.and_call_original

expect(con).to receive(:exec_query) do |query|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this change is causing a failure for this matrix run: https://github.com/instacart/makara/pull/283/checks?check_run_id=1730065278

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this spec flaps on jruby for some reason. It's the same on master now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlarraz mlarraz merged commit 14dec40 into master Jan 19, 2021
@mlarraz mlarraz deleted the ruby_3_support branch January 19, 2021 19:36
@Kevinrob Kevinrob mentioned this pull request Apr 19, 2021
mlarraz added a commit that referenced this pull request Jun 4, 2021
elsif con.respond_to?(m, true)
con.__send__(m, *args, &block)
if con.respond_to?(m, true)
con.send(m, *args, &block)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subtle regression here. We'll now call a private #foo method on the ConnectionWrapper instead of calling the public #foo method on the wrapped ConnectionAdapter. That's because using #send will dispatch the private method immediately whereas #public_send will fall back to method_missing, which is where the Makara ConnectionWrapper talks to the AR ConnectionWrapper.

Example

c.send(:select, "select 1")
*** TypeError Exception: wrong argument type String (expected Array)

c.public_send(:select, "select 1")
   (2.1ms)  select 1
#<ActiveRecord::Result:0x00007f8784b4e7f0 @columns=["1"], @rows=[[1]], @hash_rows=nil, @column_types={}>

This is the cause of #326

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. TIL about #send not hitting #method_missing.

If you can send a PR and maybe add a spec to prevent a regression I'll get it merged ASAP.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. Thanks @mlarraz.

jeromedalbert added a commit to stackshareio/makara that referenced this pull request Feb 21, 2024
gohkhoonhiang pushed a commit to coingecko/makara that referenced this pull request Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants