Skip to content
This repository

`disable_referential_integrity` failing with postgres and :truncation strategy #117

Closed
mhaylock opened this Issue May 03, 2012 · 13 comments

5 participants

Mark Haylock Ben Mabey Iain Beeston Tiago Bastos Gabriel Sobrinho
Mark Haylock

We are using database_cleaner 0.7.2 with cucumber and are using the :truncation strategy - set up as suggested by README.textile.

We haven't had any issues with this setup until yesterday when one of our tests that uses capybara + poltergeist started failing intermittently.

Most of the time it will fail, sometime it passes. The point of failure is not the test itself but the After hook when database cleaner is trying to clean the database. The error is always one of the following:

NoMethodError: undefined method `nfields' for nil:NilClass:           SELECT tablename
          FROM pg_tables
          WHERE schemaname = ANY (current_schemas(false))
 (ActiveRecord::StatementInvalid)
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:602:in `result_as_array'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:645:in `block in query'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:644:in `query'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:780:in `tables'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/truncation.rb:139:in `tables_to_truncate'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/truncation.rb:132:in `block in clean'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:526:in `disable_referential_integrity'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/truncation.rb:131:in `clean'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/database_cleaner-0.7.2/lib/database_cleaner/base.rb:77:in `clean'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/database_cleaner-0.7.2/lib/database_cleaner/configuration.rb:56:in `block in clean'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/database_cleaner-0.7.2/lib/database_cleaner/configuration.rb:56:in `each'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/database_cleaner-0.7.2/lib/database_cleaner/configuration.rb:56:in `clean'
/Users/mark/code/project/features/support/hooks/database_cleaner.rb:14:in `After'

or this error, where the number "20" can be substituted for any seemingly random number (but perhaps a number relating the id of a recently inserted row?):

PG::Error: ERROR:  relation "20" does not exist
: ALTER TABLE "20" DISABLE TRIGGER ALL (ActiveRecord::StatementInvalid)
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:653:in `async_exec'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:653:in `block in execute'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:652:in `execute'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:524:in `disable_referential_integrity'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/truncation.rb:131:in `clean'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/database_cleaner-0.7.2/lib/database_cleaner/base.rb:77:in `clean'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/database_cleaner-0.7.2/lib/database_cleaner/configuration.rb:56:in `block in clean'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/database_cleaner-0.7.2/lib/database_cleaner/configuration.rb:56:in `each'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/database_cleaner-0.7.2/lib/database_cleaner/configuration.rb:56:in `clean'
/Users/mark/code/project/features/support/hooks/database_cleaner.rb:14:in `After'

As mentioned before our database_cleaner version is 0.7.2 but we also get this on 0.7.1. Our postgres server version number is 9.1.2 and our pg gem version is 0.13.2.

A google search only shows two other sources claiming to have the same problem, one is an open github issue on tinymce-rails, and a stackoverflow post (again related to tinymce-rails)... but I can't figure out how the mentioned solutions relate to our problem.

I've dug down into the code of disable_referential_integrity and it looks like the failure is when it tries to query the schema tables from postgres... but I can't fathom why this fails. Any help would be appreciated.

Iain Beeston

I'm seeing this as well - database_cleaner 0.7.0, pg 0.11.0 and postgresql 8.4.11. It's also coming up inside the after scenario hook in cucumber when I'm calling DatabaseCleaner.clean.

Have you had any luck in getting this to work?

Mark Haylock

Unfortunately not, as we only have the single test failing intermittently we have just been avoiding the issue for the time being.

Like you though @iainbeeston, we would love to get this fixed.

Mark Haylock

We recently switched our project to using mongrel as the server during cucumber tests and we have started seeing this issue crop up on more tests than just the one test we had intermittently failing when using thin as the server.

Mongrel also gives some different error messages, here is an error for the same test failing in mongrel (looks like it could be the same thing as the 'nfields' error listed above:

2012-05-30 09:09:56 +1200: Read error: #<ActionView::Template::Error: NoMethodError: undefined method `fields' for nil:NilClass: SELECT "countries".* FROM "countries" INNER JOIN "admin_users_countries" ON "countries"."id" = "admin_users_countries"."country_id" WHERE "admin_users_countries"."admin_user_id" = 1>
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:666:in `block in exec_query'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:662:in `exec_query'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1234:in `select'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:61:in `block in select_all'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:75:in `cache_sql'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:61:in `select_all'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/querying.rb:38:in `block in find_by_sql'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/explain.rb:40:in `logging_query_plan'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/querying.rb:37:in `find_by_sql'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/relation.rb:171:in `exec_queries'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/relation.rb:160:in `block in to_a'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/explain.rb:40:in `logging_query_plan'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/relation.rb:159:in `to_a'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:159:in `all'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/associations/collection_association.rb:380:in `find_target'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/associations/collection_association.rb:333:in `load_target'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/associations/collection_proxy.rb:44:in `load_target'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/associations/collection_proxy.rb:87:in `method_missing'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/helpers/form_options_helper.rb:364:in `options_from_collection_for_select'
/Users/mark/code/example/app/views/admin/header/_country_switcher.html.erb:3:in `block in _app_views_admin_header__country_switcher_html_erb__2930598491038104749_70146356128580'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/helpers/capture_helper.rb:40:in `capture'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/helpers/form_tag_helper.rb:643:in `form_tag_in_block'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/helpers/form_tag_helper.rb:62:in `form_tag'
/Users/mark/code/example/app/views/admin/header/_country_switcher.html.erb:1:in `_app_views_admin_header__country_switcher_html_erb__2930598491038104749_70146356128580'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/template.rb:143:in `block in render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications.rb:125:in `instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/template.rb:141:in `render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/partial_renderer.rb:257:in `render_partial'
/Users/mark/code/example/features/support/disable_facebook_javascript_sdk.rb:6:in `render_partial'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/partial_renderer.rb:230:in `block in render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications.rb:123:in `block in instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications.rb:123:in `instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/partial_renderer.rb:229:in `render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/renderer.rb:41:in `render_partial'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/helpers/rendering_helper.rb:27:in `render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/builder.rb:45:in `method_missing'
/Users/mark/code/example/vendor/extensions/active_admin/views/utility_nav.rb:11:in `build'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/builder.rb:63:in `build_tag'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/builder.rb:77:in `insert_tag'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/views/header.rb:26:in `build_utility_navigation'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/views/header.rb:13:in `build'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/builder.rb:63:in `build_tag'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/builder.rb:77:in `insert_tag'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/views/pages/base.rb:49:in `build_header'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/views/pages/base.rb:39:in `block (2 levels) in build_page'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/builder.rb:68:in `block in build_tag'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/builder.rb:96:in `with_current_dom_context'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/builder.rb:67:in `build_tag'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/builder.rb:77:in `insert_tag'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/html/element.rb:17:in `div'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/views/pages/base.rb:38:in `block in build_page'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/builder.rb:96:in `with_current_dom_context'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/views/pages/base.rb:37:in `build_page'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/views/pages/base.rb:10:in `build'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/builder.rb:63:in `build_tag'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/builder.rb:77:in `insert_tag'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/arbre/builder.rb:41:in `method_missing'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/app/views/active_admin/dashboard/index.html.arb:1:in `___sers_mark__rvm_gems_ruby_______p____bundler_gems_active_admin__d_e__c_f__e_app_views_active_admin_dashboard_index_html_arb___3187927278339156525_70146365660520'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/template.rb:143:in `block in render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications.rb:125:in `instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/template.rb:141:in `render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/template_renderer.rb:42:in `block (2 levels) in render_template'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications.rb:123:in `block in instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications.rb:123:in `instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/template_renderer.rb:41:in `block in render_template'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/template_renderer.rb:49:in `render_with_layout'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/template_renderer.rb:40:in `render_template'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/template_renderer.rb:13:in `render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/renderer.rb:36:in `render_template'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_view/renderer/renderer.rb:17:in `render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/abstract_controller/rendering.rb:109:in `_render_template'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/streaming.rb:225:in `_render_template'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/abstract_controller/rendering.rb:103:in `render_to_body'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/renderers.rb:28:in `render_to_body'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/abstract_controller/rendering.rb:88:in `render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/rendering.rb:16:in `render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/Users/mark/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/core_ext/benchmark.rb:5:in `ms'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/instrumentation.rb:40:in `block in render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/instrumentation.rb:39:in `render'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/refinerycms-pages-2.0.3/lib/refinery/pages/instance_methods.rb:28:in `render_with_presenters'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/bundler/gems/active_admin-4d3e05c7f56e/lib/active_admin/dashboards/dashboard_controller.rb:9:in `index'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/abstract_controller/base.rb:167:in `process_action'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/rendering.rb:10:in `process_action'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:480:in `_run__2268729970934775700__process_action__276815756612910056__callbacks'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/abstract_controller/callbacks.rb:17:in `process_action'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/rescue.rb:29:in `process_action'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications.rb:123:in `block in instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/notifications.rb:123:in `instrument'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/abstract_controller/base.rb:121:in `process'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/abstract_controller/rendering.rb:45:in `process'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal.rb:203:in `dispatch'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_controller/metal.rb:246:in `block in action'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:67:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:67:in `dispatch'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:30:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/journey-1.0.3/lib/journey/router.rb:68:in `block in call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/journey-1.0.3/lib/journey/router.rb:56:in `each'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/journey-1.0.3/lib/journey/router.rb:56:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:594:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:392:in `call_app!'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:258:in `mock_call!'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:171:in `call!'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:157:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/warden-1.1.1/lib/warden/manager.rb:35:in `block in call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/warden-1.1.1/lib/warden/manager.rb:34:in `catch'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/warden-1.1.1/lib/warden/manager.rb:34:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/etag.rb:23:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/conditionalget.rb:25:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/middleware/head.rb:14:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/middleware/flash.rb:242:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/middleware/cookies.rb:338:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/dragonfly-0.9.12/lib/dragonfly/cookie_monster.rb:9:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/query_cache.rb:64:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:405:in `_run__1871085017695589795__call__3628915031162237367__callbacks'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/dragonfly-0.9.12/lib/dragonfly/middleware.rb:13:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/cucumber-rails-1.0.6/lib/cucumber/rails/action_controller.rb:10:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/rack/logger.rb:26:in `call_app'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/rack/logger.rb:16:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/middleware/request_id.rb:22:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/dragonfly-0.9.12/lib/dragonfly/middleware.rb:13:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-cache-1.2/lib/rack/cache/context.rb:245:in `fetch'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-cache-1.2/lib/rack/cache/context.rb:185:in `lookup'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in `call!'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/middleware/static.rb:61:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/engine.rb:479:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/application.rb:220:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/builder.rb:134:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/urlmap.rb:64:in `block in call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/urlmap.rb:49:in `each'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/urlmap.rb:49:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/capybara-1.1.2/lib/capybara/server.rb:17:in `call'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/handler/mongrel.rb:77:in `process'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:165:in `block in process_client'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:164:in `each'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:164:in `process_client'
/Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/mongrel-1.2.0.pre2/lib/mongrel.rb:291:in `block (2 levels) in run'
Iain Beeston

I've just realised that I'm no longer getting this error, but unfortunately I can't remember what I changed to fix it. Maybe we can work it out by a process of elimination. Have you configured support/env.rb and support/hooks.rb (or similar) as described here?

Also, I'm using poltergeist 0.6.0 and capybara 1.1.2.

Mark Haylock

Hi @iainbeeston, yes we have a setup like the one linked to in the example. We are using the same versions of poltergeist and capybara as you also.

Is there any chance you would be able to use git bisect to identify a commit that fixed the problem for you?

Iain Beeston

I'm afraid there are hundreds of commits since we had that issue. However, I might have found it again by chance. As it happens I've switched back from using poltergeist to capybara-webkit and now I'm getting the error again. Mysterious...

Iain Beeston

I've been tinkering with this a little more - I think I might have reproduced this problem by calling only DatabaseCleaner.clean, without calling DatabaseCleaner.start as well (my thinking was that for truncation surely we don't need to call start?)

Tiago Bastos
bastos commented July 27, 2012

I'm getting the same error:

Failure/Error: Unable to find matching line from backtrace
 ActiveRecord::StatementInvalid:
   NoMethodError: undefined method `nfields' for nil:NilClass:           SELECT tablename
             FROM pg_tables
             WHERE schemaname = ANY (current_schemas(false))

On my spec helper:

config.before(:suite) do
  DatabaseCleaner.strategy = :truncation
end

config.before(:each) do
  DatabaseCleaner.start
end

config.after(:each) do
  DatabaseCleaner.clean
end

Stack trace: https://gist.github.com/843e537c43f3b277509c

pg (0.13.2)
database_cleaner (0.8.0)
capybara (1.1.2)
rails (3.2.6)
rspec (2.10.0)

Iain Beeston

I finally found the solution to this one - the problem (for me at least) is a duplicate of cucumber/cucumber-rails#166. Re-generating my env.rb file using the cucumber-rails generators (eg. rails generate cucumber:install) fixed it. The difference was in the default db cleaner strategy used for javascript tagged scenarios, so it wasn't a problem with db cleaner but rather with cucumber-rails

Mark Haylock

@iainbeeston thanks, using that link we found a combination that works for us:

# From https://github.com/cucumber/cucumber-rails/issues/166#issuecomment-2548522
Before('@javascript') do
  ActiveRecord::Base.shared_connection = nil
  ActiveRecord::Base.descendants.each do |model|
    model.shared_connection = nil
  end
end

combined with:

Cucumber::Rails::Database.javascript_strategy = :truncation

We tried it without the shared_connection hack above and it didn't work, we also tried setting the javascript_strategy to :shared_connection but that had issues as well. So for our purposes we will leave it as we have it above. Not sure if I should close this if our solutions differ?

Iain Beeston
Tiago Bastos
bastos commented July 30, 2012

Sorry, I've actually had this hack in my acceptance_helper.rb http://gist.github.com/470808. Now my suite is working properly using truncation only and removing the monkey patch. Still pretty slow but al least is working.

Gabriel Sobrinho

Guys,

This issue happen due to a race condition on pg adapter using shared connection hack.

Instead of slowing down the entire suite to use database cleaner, I'm currently using this setup:

RSpec.configure do |config|
  config.before do
    DatabaseCleaner.strategy = if example.metadata[:type] == :request
                                 :truncation
                               else
                                 :transaction
                               end

    DatabaseCleaner.start
  end

  config.after do
    DatabaseCleaner.clean
  end
end

This works well for unit tests using transaction and truncation for request specs.

I guess a similar approach could be taken to use on cucumber.

@bmabey could you close that issue? :)

Ben Mabey bmabey closed this August 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.