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

ActiveRecord::StatementInvalid: ArgumentError: wrong number of arguments (1 for 2) for invokedynamic #3528

Closed
lephyrius opened this issue Dec 10, 2015 · 2 comments

Comments

@lephyrius
Copy link

Sorry for the cross post: jruby/activerecord-jdbc-adapter#691
I got this error on:
jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa Java HotSpot(TM) 64-Bit Server VM 25.66-b17 on 1.8.0_66-b17 +indy +jit [darwin-x86_64]
Here is my JRUBY_OPTS:
export JRUBY_OPTS="-J-Xmn512m -J-Xms2048m -J-Xmx2048m -J-XX:+UseConcMarkSweepGC -Xcompile.invokedynamic=true"

Here is a pretty isolated testcase you just need to create the "test_ar" database:

begin
  require 'bundler/inline'
rescue LoadError => e
  $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
  raise e
end

gemfile(true) do
  source 'https://rubygems.org'
  # Activate the gem you are reporting the issue against.
  gem 'activerecord', '4.2.5'
  gem 'activerecord-jdbcpostgresql-adapter'
end

require 'active_record'
require 'minitest/autorun'
require 'logger'

# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)

# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'test_ar')
ActiveRecord::Base.logger = Logger.new(STDOUT)


ActiveRecord::Schema.define do
  begin
    drop_table :posts
    drop_table :comments
    drop_table :users
  rescue ActiveRecord::StatementInvalid

  end
  create_table :posts, force: true do |t|

  end
  create_table :comments, force: true do |t|
    t.integer :post_id
    t.integer :user_id
  end

  create_table :users, force: true do |t|
    t.string :username
  end

end

class Post < ActiveRecord::Base
  has_many :comments
  has_many :users, through: :comments
end

class Comment < ActiveRecord::Base
  belongs_to :post
  belongs_to :user
end

class User < ActiveRecord::Base
  has_many :comments
end


class BugTest < Minitest::Test
  def test_association_stuff
    post = Post.create!
    user = User.create! username: 'cool user'
    post.comments << Comment.create!(user_id: user.id)
    post.comments << Comment.create!
    post.comments << Comment.create!(user_id: user.id)
    post.comments << Comment.create!
    post.comments << Comment.create!(user_id: user.id)
    post.comments << Comment.create!
    post.comments << Comment.create!(user_id: user.id)

    post.reload

    10000.times do
      post.reload

      post.users.order(:username).pluck(:username).map do |username|

        username
      end

    end

  end

  def teardown
    Post.delete_all
    Comment.delete_all
    User.delete_all
  end
end

if I run it I get:

Finished in 2.094541s, 0.4774 runs/s, 0.0000 assertions/s.

  1) Error:
BugTest#test_association_stuff:
ActiveRecord::StatementInvalid: ArgumentError: wrong number of arguments (1 for 2): SELECT  "posts".* FROM "posts" WHERE "posts"."id" = 1 LIMIT 1
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-jdbc-adapter-1.3.19/lib/arjdbc/jdbc/adapter.rb:455:in `block in exec_query'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-jdbc-adapter-1.3.19/lib/arjdbc/jdbc/adapter.rb:455:in `exec_query'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-jdbc-adapter-1.3.19/lib/arjdbc/jdbc/adapter.rb:542:in `select'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/querying.rb:39:in `find_by_sql'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/relation.rb:639:in `exec_queries'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/relation.rb:515:in `load'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/relation.rb:243:in `to_a'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/relation/finder_methods.rb:475:in `find_take'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/relation/finder_methods.rb:105:in `take'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/relation/finder_methods.rb:442:in `find_one'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/relation/finder_methods.rb:423:in `find_with_ids'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/relation/finder_methods.rb:71:in `find'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/querying.rb:3:in `find'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/core.rb:131:in `find'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/persistence.rb:416:in `block in reload'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/scoping/default.rb:33:in `block in unscoped'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/relation.rb:302:in `scoping'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/scoping/default.rb:33:in `unscoped'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/persistence.rb:416:in `reload'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/attribute_methods/dirty.rb:36:in `reload'
    /usr/local/var/rbenv/versions/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/autosave_association.rb:227:in `reload'
    test_has_many.rb:80:in `block in test_association_stuff'
    org/jruby/RubyFixnum.java:301:in `times'
    test_has_many.rb:79:in `test_association_stuff'

I'm thinking it's either jRuby invokedynamic that is wrong or it's activerecord-jdbc that doesn't work with invokedynamic.

@kares
Copy link
Member

kares commented Jan 18, 2017

do we fix this at JRuby's (obviously dispatch does not match with native overloads when using indy) ?
... or shall we hack around at AR-JDBC's - no one else seems to have hit the issue thus far ?
// cc @enebo @headius

@headius
Copy link
Member

headius commented Feb 24, 2017

This appears to have been fixed by other invokedynamic patches already pushed for 9.1.8.0. Thanks for the excellent repro script!

@headius headius closed this as completed Feb 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants