Search code examples
ruby-on-railsrubyrubygemsrails-activerecordactiverecord-jdbc

activerecord-postgis-adapter: #<ArgumentError: wrong number of arguments (3 for 4)>


Problem Description

I'm trying to migrate an existing Ruby on Rails App (Ruby 2.3.3p222, Rails 5.0.0.1), developed by an former colleague, to JRuby. The app is running without any issues using aforementioned Ruby version. You can find the original Gemfile as Gemfile Ruby in the appendix.

As I'm new to Ruby and not sure about what's wrong, I provide all the changes I did so far (see Gemfile JRuby in the appendix for the resulting Gemfile) to migrate the app to JRuby.

1. Replacement of gem 'pg'

I replaced gem 'pg', '~> 0.21.0' by

gem 'pg', '0.21.0', :platform => :jruby, :git => 'git://github.com/headius/jruby-pg.git', :branch => :master

as instructed at the Github page of jruby-pg. After running bundle install, I started the application which showed the error:

LoadError: no such file to load -- active_record/connection_adapters/jdbcpostgresql_adapter

2. Adaption of gem 'activerecord-postgis-adapter'

To get rid of the last error, I appended to the line gem 'activerecord-postgis-adapter' the following:

gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.9'
gem 'ffi-geos'

as suggested by the Github page of activerecord-postgis-adapter. Again, after bundler install and running, I get an error:

Bundler::GemRequireError: There was an error while trying to load the gem 'activerecord-postgis-adapter'.
Gem Load Error is: uninitialized constant ActiveRecord::ConnectionAdapters::Column::Format

Solution Approach

I tried to follow the hint given in this post and replaced the gem 'activerecord-jdbcpostgresql-adapter line by

gem 'activerecord-jdbcpostgresql-adapter', :git => "git://github.com/jruby/activerecord-jdbc-adapter.git",
:branch => "50-stable", :platform => :jruby

Due to the following errors, I removed the gem ffi-geos and the errors disappeared:

Error:[rake --tasks] C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:9: warning: already initialized constant GEOS_BASE
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:90: warning: already initialized constant DimensionTypes
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:99: warning: already initialized constant ByteOrders
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:104: warning: already initialized constant BufferCapStyles
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:110: warning: already initialized constant BufferJoinStyles
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:116: warning: already initialized constant ValidFlags
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:120: warning: already initialized constant RelateBoundaryNodeRules
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:128: warning: already initialized constant GeometryTypes
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:139: warning: already initialized constant PrecisionOptions
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:786: warning: already initialized constant FFI_LAYOUT
rake aborted!
LoadError: Couldn't load the GEOS CAPI library.
... stacktrace ...

Finally I could run the application, however, sending a POST request returns the following error

2018-09-06 14:08:17 +0200: Rack app error handling request { POST /tripplanner/api/trip_proposals }

#<ArgumentError: wrong number of arguments (3 for 4)>
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/activerecord-postgis-adapter-4.0.2/lib/active_record/connection_adapters/postgis_adapter.rb:12:in `initialize'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/bundler/gems/activerecord-jdbc-adapter-9dbcf040715b/lib/arjdbc/jdbc/callbacks.rb:12:in `new'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/bundler/gems/activerecord-jdbc-adapter-9dbcf040715b/lib/arjdbc/jdbc/connection_methods.rb:8:in `jdbc_connection'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/bundler/gems/activerecord-jdbc-adapter-9dbcf040715b/lib/arjdbc/postgresql/connection_methods.rb:64:in `postgresql_connection'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/activerecord-postgis-adapter-4.0.2/lib/active_record/connection_adapters/postgis/create_connection.rb:13:in `postgis_connection'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:721:in `new_connection'
... stacktrace ...

I could only find this issue in activerecord-jdbc-adapter but it doesn't state any solution. As I have no plan on how to proceed, do you have any idea about the cause of the error? Thanks a lot!


Appendix

Version Information

The development machine is running on Windows 10 (x64) and using RubyMine 2018.2.1 as IDE. Parallel to JRuby, Ruby 2.3.3 is still installed (using RailsInstaller). However, the IDE is configured to use JRuby as project's SDK.

  • Java JDK 1.8.0_172
  • JRuby 9.1.17.0-p0
  • PostgreSQL x64 9.5 with PostGIS 2.3.5 r16110, GEOS 3.6.2-CAPI-1.10.2 4d2925d
  • Puma 3.6.0

Gemfiles

Gemfile Ruby

source 'https://rubygems.org'

gem 'rails', '~> 5.0.0', '>= 5.0.0.1'

# Use postgresql as the database for Active Record
gem 'pg', '~> 0.21.0'

# Use Puma as the app server
gem 'puma', '~> 3.0'
gem 'config'
gem 'whenever', :require => false

# gems for database handling
gem 'activerecord-postgis-adapter'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
end

group :development do
  gem 'listen', '~> 3.0.5'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'

  gem 'mina'
  gem 'mina-puma', github: 'untitledkingdom/mina-puma'
  gem 'mina-whenever'
end

group :test do
  gem 'whenever-test'
  gem 'mocha'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'active_model_serializers'
gem 'httparty'
gem 'polylines'

Gemfile JRuby

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'

# Use postgresql as the database for Active Record
gem 'pg', '0.21.0', :platform => :jruby, :git => 'git://github.com/headius/jruby-pg.git', :branch => :master

# Use Puma as the app server
gem 'puma', '~> 3.0'
gem 'config'
gem 'whenever', :require => false

# gems for database handling
gem 'activerecord-postgis-adapter'
#gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.9'
gem 'activerecord-jdbcpostgresql-adapter', :git => "git://github.com/jruby/activerecord-jdbc-adapter.git",
    :branch => "50-stable", :platform => :jruby
#gem 'ffi-geos'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
end

group :development do
  gem 'listen', '~> 3.0.5'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'

  gem 'mina'
  gem 'mina-puma', github: 'untitledkingdom/mina-puma'
  gem 'mina-whenever'
end

group :test do
  gem 'whenever-test'
  gem 'mocha'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'active_model_serializers'
gem 'httparty'
gem 'polylines'

Solution

  • The issue was related to the gem activerecord-jdbc-adapter and could be solved in issue #891. As all changes were made on branch 50-stable, no change of the Gemfile was required. The app is now running in JRuby :-)