activerecord-jdbc-adapter icon indicating copy to clipboard operation
activerecord-jdbc-adapter copied to clipboard

NoMethodError: undefined method 'to_sql' for nil:NilClass

Open Shrimi opened this issue 9 years ago • 3 comments

NoMethodError: undefined method 'to_sql' for nil:NilClass The server starts fine and the application is running, I only get the above error while trying to load a particular grid.

Gemfile: gem 'rails', '4.2.7.1' gem 'activerecord-jdbc-adapter'

Full trace: _activerecord-jdbc-adapter (1.3.20) lib/arjdbc/mssql/adapter.rb:468:in block in columns_for_distinct' org/jruby/RubyArray.java:2524:inmap!' activerecord-jdbc-adapter (1.3.20) lib/arjdbc/mssql/adapter.rb:467:in columns_for_distinct' activerecord (4.2.7.1) lib/active_record/relation/finder_methods.rb:396:inlimited_ids_for' activerecord (4.2.7.1) lib/active_record/relation/finder_methods.rb:387:in apply_join_dependency' activerecord (4.2.7.1) lib/active_record/relation/finder_methods.rb:347:infind_with_associations' activerecord (4.2.7.1) lib/active_record/relation.rb:639:in exec_queries' activerecord (4.2.7.1) lib/active_record/relation.rb:515:inload' activerecord (4.2.7.1) lib/active_record/relation.rb:243:in to_a' activerecord (4.2.7.1) lib/active_record/relation/delegation.rb:46:ineach' /Users/ssharma/wice_grid/lib/wice_grid.rb:382:in each' /Users/ssharma/wice_grid/lib/wice/helpers/wice_grid_view_helpers.rb:423:ingrid_html' /Users/ssharma/wice_grid/lib/wice/helpers/wice_grid_view_helpers.rb:124:in define_grid' /Users/ssharma/wice_grid/lib/wice/helpers/wice_grid_view_helpers.rb:74:ingrid' app/views/findings/_grid.html.erb:5:in _app_views_findings__grid_html_erb__1198539952_7620' actionview (4.2.7.1) lib/action_view/template.rb:145:inblock in render' activesupport (4.2.7.1) lib/active_support/notifications.rb:166:in instrument' actionview (4.2.7.1) lib/action_view/template.rb:333:ininstrument' actionview (4.2.7.1) lib/action_view/template.rb:143:in render' actionview (4.2.7.1) lib/action_view/renderer/partial_renderer.rb:339:inrender_partial' actionview (4.2.7.1) lib/action_view/renderer/partial_renderer.rb:310:in block in render' actionview (4.2.7.1) lib/action_view/renderer/abstract_renderer.rb:39:inblock in instrument' activesupport (4.2.7.1) lib/active_support/notifications.rb:164:in block in instrument' activesupport (4.2.7.1) lib/active_support/notifications/instrumenter.rb:20:ininstrument' activesupport (4.2.7.1) lib/active_support/notifications.rb:164:in instrument' actionview (4.2.7.1) lib/action_view/renderer/abstract_renderer.rb:39:ininstrument' actionview (4.2.7.1) lib/action_view/renderer/partial_renderer.rb:309:in render' actionview (4.2.7.1) lib/action_view/renderer/renderer.rb:51:inrender_partial' actionview (4.2.7.1) lib/action_view/helpers/rendering_helper.rb:35:in render' app/views/findings/_index.html.erb:40:in_app_views_findings__index_html_erb__1571398616_7618' actionview (4.2.7.1) lib/action_view/template.rb:145:in block in render' activesupport (4.2.7.1) lib/active_support/notifications.rb:166:ininstrument' actionview (4.2.7.1) lib/action_view/template.rb:333:in instrument' actionview (4.2.7.1) lib/action_view/template.rb:143:inrender' actionview (4.2.7.1) lib/action_view/renderer/partial_renderer.rb:339:in render_partial' actionview (4.2.7.1) lib/action_view/renderer/partial_renderer.rb:310:inblock in render' actionview (4.2.7.1) lib/action_view/renderer/abstract_renderer.rb:39:in block in instrument' activesupport (4.2.7.1) lib/active_support/notifications.rb:164:inblock in instrument' activesupport (4.2.7.1) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.2.7.1) lib/active_support/notifications.rb:164:ininstrument' actionview (4.2.7.1) lib/action_view/renderer/abstract_renderer.rb:39:in instrument' actionview (4.2.7.1) lib/action_view/renderer/partial_renderer.rb:309:inrender' actionview (4.2.7.1) lib/action_view/renderer/renderer.rb:51:in render_partial' actionview (4.2.7.1) lib/action_view/helpers/rendering_helper.rb:35:inrender' app/views/findings/index.html.erb:2:in _app_views_findings_index_html_erb__2145172622_7614' actionview (4.2.7.1) lib/action_view/template.rb:145:inblock in render' activesupport (4.2.7.1) lib/active_support/notifications.rb:166:in instrument' actionview (4.2.7.1) lib/action_view/template.rb:333:ininstrument' actionview (4.2.7.1) lib/action_view/template.rb:143:in render' actionview (4.2.7.1) lib/action_view/renderer/template_renderer.rb:54:inblock in render_template' actionview (4.2.7.1) lib/action_view/renderer/abstract_renderer.rb:39:in block in instrument' activesupport (4.2.7.1) lib/active_support/notifications.rb:164:inblock in instrument' activesupport (4.2.7.1) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.2.7.1) lib/active_support/notifications.rb:164:ininstrument' actionview (4.2.7.1) lib/action_view/renderer/abstract_renderer.rb:39:in instrument' actionview (4.2.7.1) lib/action_view/renderer/template_renderer.rb:53:inblock in render_template' actionview (4.2.7.1) lib/action_view/renderer/template_renderer.rb:61:in render_with_layout' actionview (4.2.7.1) lib/action_view/renderer/template_renderer.rb:52:inrender_template' actionview (4.2.7.1) lib/action_view/renderer/template_renderer.rb:14:in render' actionview (4.2.7.1) lib/action_view/renderer/renderer.rb:46:inrender_template' actionview (4.2.7.1) lib/action_view/renderer/renderer.rb:27:in render' actionview (4.2.7.1) lib/action_view/rendering.rb:100:in_render_template' actionpack (4.2.7.1) lib/action_controller/metal/streaming.rb:217:in _render_template' actionview (4.2.7.1) lib/action_view/rendering.rb:83:inrender_to_body' actionpack (4.2.7.1) lib/action_controller/metal/rendering.rb:32:in render_to_body' actionpack (4.2.7.1) lib/action_controller/metal/renderers.rb:37:inrender_to_body' actionpack (4.2.7.1) lib/abstract_controller/rendering.rb:25:in render' actionpack (4.2.7.1) lib/action_controller/metal/rendering.rb:16:inrender' actionpack (4.2.7.1) lib/action_controller/metal/instrumentation.rb:44:in block in render' activesupport (4.2.7.1) lib/active_support/core_ext/benchmark.rb:12:inblock in ms' /Users/ssharma/.rvm/rubies/jruby-9.1.5.0/lib/ruby/stdlib/benchmark.rb:308:in realtime' activesupport (4.2.7.1) lib/active_support/core_ext/benchmark.rb:12:inms' actionpack (4.2.7.1) lib/action_controller/metal/instrumentation.rb:44:in block in render' actionpack (4.2.7.1) lib/action_controller/metal/instrumentation.rb:87:incleanup_view_runtime' activerecord (4.2.7.1) lib/active_record/railties/controller_runtime.rb:25:in cleanup_view_runtime' actionpack (4.2.7.1) lib/action_controller/metal/instrumentation.rb:43:inrender' remotipart (1.2.1) lib/remotipart/render_overrides.rb:14:in render_with_remotipart' actionpack (4.2.7.1) lib/action_controller/metal/implicit_render.rb:10:indefault_render' actionpack (4.2.7.1) lib/action_controller/metal/implicit_render.rb:5:in send_action' actionpack (4.2.7.1) lib/abstract_controller/base.rb:198:inprocess_action' actionpack (4.2.7.1) lib/action_controller/metal/rendering.rb:10:in process_action' actionpack (4.2.7.1) lib/abstract_controller/callbacks.rb:20:inblock in process_action' activesupport (4.2.7.1) lib/active_support/callbacks.rb:117:in call' activesupport (4.2.7.1) lib/active_support/callbacks.rb:555:inblock in compile' activesupport (4.2.7.1) lib/active_support/callbacks.rb:505:in call' activesupport (4.2.7.1) lib/active_support/callbacks.rb:92:inrun_callbacks' activesupport (4.2.7.1) lib/active_support/callbacks.rb:778:in _run_process_action_callbacks' activesupport (4.2.7.1) lib/active_support/callbacks.rb:81:inrun_callbacks' actionpack (4.2.7.1) lib/abstract_controller/callbacks.rb:19:in process_action' actionpack (4.2.7.1) lib/action_controller/metal/rescue.rb:29:inprocess_action' actionpack (4.2.7.1) lib/action_controller/metal/instrumentation.rb:32:in block in process_action' activesupport (4.2.7.1) lib/active_support/notifications.rb:164:inblock in instrument' activesupport (4.2.7.1) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.2.7.1) lib/active_support/notifications.rb:164:ininstrument' actionpack (4.2.7.1) lib/action_controller/metal/instrumentation.rb:30:in process_action' actionpack (4.2.7.1) lib/action_controller/metal/params_wrapper.rb:250:inprocess_action' activerecord (4.2.7.1) lib/active_record/railties/controller_runtime.rb:18:in process_action' actionpack (4.2.7.1) lib/abstract_controller/base.rb:137:inprocess' actionview (4.2.7.1) lib/action_view/rendering.rb:30:in process' actionpack (4.2.7.1) lib/action_controller/metal.rb:196:indispatch' actionpack (4.2.7.1) lib/action_controller/metal/rack_delegation.rb:13:in dispatch' actionpack (4.2.7.1) lib/action_controller/metal.rb:237:inblock in action' actionpack (4.2.7.1) lib/action_dispatch/routing/route_set.rb:74:in dispatch' actionpack (4.2.7.1) lib/action_dispatch/routing/route_set.rb:43:inserve' actionpack (4.2.7.1) lib/action_dispatch/journey/router.rb:43:in block in serve' actionpack (4.2.7.1) lib/action_dispatch/journey/router.rb:30:inserve' actionpack (4.2.7.1) lib/action_dispatch/routing/route_set.rb:817:in call' apipie-rails (0.3.6) lib/apipie/static_dispatcher.rb:65:incall' omniauth (1.3.1) lib/omniauth/strategy.rb:186:in call!' omniauth (1.3.1) lib/omniauth/strategy.rb:164:incall' apipie-rails (0.3.6) lib/apipie/extractor/recorder.rb:132:in call' client_side_validations (4.2.5) lib/client_side_validations/middleware.rb:15:incall' warden (1.2.6) lib/warden/manager.rb:35:in block in call' org/jruby/RubyKernel.java:1115:incatch' warden (1.2.6) lib/warden/manager.rb:34:in call' rack (1.6.4) lib/rack/etag.rb:24:incall' breach-mitigation-rails (0.2.2) lib/breach_mitigation/length_hiding.rb:10:in call' rack (1.6.4) lib/rack/conditionalget.rb:25:incall' rack (1.6.4) lib/rack/head.rb:13:in call' remotipart (1.2.1) lib/remotipart/middleware.rb:27:incall' actionpack (4.2.7.1) lib/action_dispatch/middleware/params_parser.rb:27:in call' actionpack (4.2.7.1) lib/action_dispatch/middleware/flash.rb:260:incall' torquebox-web-3.2.0 (java) lib/torquebox/session/servlet_store.rb:47:in call' actionpack (4.2.7.1) lib/action_dispatch/middleware/cookies.rb:560:incall' activerecord (4.2.7.1) lib/active_record/query_cache.rb:36:in call' activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:incall' activerecord (4.2.7.1) lib/active_record/migration.rb:377:in call' actionpack (4.2.7.1) lib/action_dispatch/middleware/callbacks.rb:29:inblock in call' activesupport (4.2.7.1) lib/active_support/callbacks.rb:88:in __run_callbacks__' activesupport (4.2.7.1) lib/active_support/callbacks.rb:778:inrun_call_callbacks' activesupport (4.2.7.1) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (4.2.7.1) lib/action_dispatch/middleware/callbacks.rb:27:incall' actionpack (4.2.7.1) lib/action_dispatch/middleware/reloader.rb:73:in call' actionpack (4.2.7.1) lib/action_dispatch/middleware/remote_ip.rb:78:incall'

As a temporary fix I have modified the following file: /activerecord-jdbc-adapter-1.3.21/lib/arjdbc/mssql/adapter.rb (line 468) to check for nil. Everything works fine then.

I believe this is an adapter issue, though I'm far from sure.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/37978012-nomethoderror-undefined-method-to_sql-for-nil-nilclass?utm_campaign=plugin&utm_content=tracker%2F136963&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F136963&utm_medium=issues&utm_source=github).

Shrimi avatar Sep 21 '16 18:09 Shrimi

i also am facing a very similar issue 👍

amudgal avatar Sep 23 '16 01:09 amudgal

jruby -S bin/rake db:migrate RAILS_ENV=development --trace ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Invoke db:load_config (first_time) ** Execute db:load_config ** Execute db:migrate rake aborted! NoMethodError: undefined method accept' for nil:NilClass /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:12:into_sql' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in select_all' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/query_cache.rb:70:inselect_all' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/querying.rb:39:in find_by_sql' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/relation.rb:699:inexec_queries' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/relation.rb:580:in load' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/relation.rb:260:inrecords' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/relation/delegation.rb:38:in map' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1030:inblock in get_all_versions' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activesupport-5.0.0.1/lib/active_support/deprecation/reporting.rb:36:in silence' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activesupport-5.0.0.1/lib/active_support/deprecation/instance_delegator.rb:19:insilence' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1028:in get_all_versions' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1162:inload_migrated' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1158:in migrated' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1196:inran?' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1140:in block in runnable' org/jruby/RubyArray.java:2717:inreject' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1140:in runnable' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1182:inmigrate_without_lock' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1133:in migrate' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:1005:inup' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:983:in migrate' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:161:inmigrate' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/railties/databases.rake:58:in block in (root)' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/rake-11.3.0/lib/rake/task.rb:248:inblock in execute' org/jruby/RubyArray.java:1734:in each' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/rake-11.3.0/lib/rake/task.rb:243:inexecute' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/rake-11.3.0/lib/rake/task.rb:187:in block in invoke_with_call_chain' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/stdlib/monitor.rb:214:inmon_synchronize' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/rake-11.3.0/lib/rake/task.rb:180:in invoke_with_call_chain' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/rake-11.3.0/lib/rake/task.rb:173:ininvoke' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/rake-11.3.0/lib/rake/application.rb:152:in invoke_task' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/rake-11.3.0/lib/rake/application.rb:108:inblock in top_level' org/jruby/RubyArray.java:1734:in each' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/rake-11.3.0/lib/rake/application.rb:108:inblock in top_level' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/rake-11.3.0/lib/rake/application.rb:117:in run_with_threads' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/rake-11.3.0/lib/rake/application.rb:102:intop_level' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/rake-11.3.0/lib/rake/application.rb:80:in block in run' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/rake-11.3.0/lib/rake/application.rb:178:instandard_exception_handling' /Users/amitmudgal/.rbenv/versions/jruby-9.1.5.0/lib/ruby/gems/shared/gems/rake-11.3.0/lib/rake/application.rb:77:in run' bin/rake:4:in

' Tasks: TOP => db:migrate

amudgal avatar Sep 23 '16 01:09 amudgal

@amudgal you are showing with 5.x adapter and I would bet this is unrelated to the original reporters issue involving 4.2.7.

@kares I removed rails-5.x because original reporter was not on 5.

enebo avatar Nov 13 '17 20:11 enebo