undefined method `extend' for class `ActiveRecord::Associations::CollectionProxy'

I have a rails 3.2.21 app hosted on Heroku, using Heroku Postgres. I got the “undefined method extend' for class ActiveRecord::Associations::CollectionProxy’” error fired from every page on one of the web dynos. After a while the dyno was restarted and everything went back to normal.

I have no idea what could cause such an error, any hint would be great.

In case you need, here is a stack trace from one of the pages:

….21/lib/active_record/associations/collection_proxy.rb: 37:in <class:CollectionProxy>' ….21/lib/active_record/associations/collection_proxy.rb: 36:in module:Associations
….21/lib/active_record/associations/collection_proxy.rb: 2:in <module:ActiveRecord>' ….21/lib/active_record/associations/collection_proxy.rb: 1:in <top (required)>’
…b/active_record/associations/collection_association.rb: 25:in initialize' …ve_record/associations/has_many_through_association.rb: 10:in initialize’
…/activerecord-3.2.21/lib/active_record/associations.rb: 160:in new' …/activerecord-3.2.21/lib/active_record/associations.rb: 160:in association’
…ib/active_record/associations/preloader/association.rb: 18:in run' …ord-3.2.21/lib/active_record/associations/preloader.rb: 132:in block (2 levels) in preload_one’
…ord-3.2.21/lib/active_record/associations/preloader.rb: 131:in each' …ord-3.2.21/lib/active_record/associations/preloader.rb: 131:in block in preload_one’
…ord-3.2.21/lib/active_record/associations/preloader.rb: 130:in each' …ord-3.2.21/lib/active_record/associations/preloader.rb: 130:in preload_one’
…ord-3.2.21/lib/active_record/associations/preloader.rb: 109:in preload' …/squeel/adapters/active_record/preloader_extensions.rb: 14:in block in run_with_squeel’
…/squeel/adapters/active_record/preloader_extensions.rb: 14:in each' …/squeel/adapters/active_record/preloader_extensions.rb: 14:in run_with_squeel’
…gems/activerecord-3.2.21/lib/active_record/relation.rb: 181:in block in exec_queries' …gems/activerecord-3.2.21/lib/active_record/relation.rb: 180:in each’
…gems/activerecord-3.2.21/lib/active_record/relation.rb: 180:in exec_queries' …gems/activerecord-3.2.21/lib/active_record/relation.rb: 160:in block in to_a’
…/gems/activerecord-3.2.21/lib/active_record/explain.rb: 41:in logging_query_plan' …gems/activerecord-3.2.21/lib/active_record/relation.rb: 159:in to_a’
…rd-3.2.21/lib/active_record/relation/finder_methods.rb: 381:in find_first' …rd-3.2.21/lib/active_record/relation/finder_methods.rb: 122:in first’
….1.0/gems/friendly_id-4.0.9/lib/friendly_id/history.rb: 92:in find_one' …rd-3.2.21/lib/active_record/relation/finder_methods.rb: 315:in find_with_ids’
…rd-3.2.21/lib/active_record/relation/finder_methods.rb: 107:in find' /app/app/controllers/programs_controller.rb: 8:in show’
…-3.2.21/lib/action_controller/metal/implicit_render.rb: 4:in send_action' …gems/actionpack-3.2.21/lib/abstract_controller/base.rb: 167:in process_action’
…onpack-3.2.21/lib/action_controller/metal/rendering.rb: 10:in process_action' …actionpack-3.2.21/lib/abstract_controller/callbacks.rb: 18:in block in process_action’
…s/activesupport-3.2.21/lib/active_support/callbacks.rb: 458:in _run__283287050225388972__process_action__1943163135672811662__callbacks' …s/activesupport-3.2.21/lib/active_support/callbacks.rb: 405:in __run_callback’
…s/activesupport-3.2.21/lib/active_support/callbacks.rb: 385:in _run_process_action_callbacks' …s/activesupport-3.2.21/lib/active_support/callbacks.rb: 81:in run_callbacks’
…actionpack-3.2.21/lib/abstract_controller/callbacks.rb: 17:in process_action' …ctionpack-3.2.21/lib/action_controller/metal/rescue.rb: 29:in process_action’
…-3.2.21/lib/action_controller/metal/instrumentation.rb: 30:in block in process_action' …tivesupport-3.2.21/lib/active_support/notifications.rb: 123:in block in instrument’
….2.21/lib/active_support/notifications/instrumenter.rb: 20:in instrument' …tivesupport-3.2.21/lib/active_support/notifications.rb: 123:in instrument’
…-3.2.21/lib/action_controller/metal/instrumentation.rb: 29:in process_action' …k-3.2.21/lib/action_controller/metal/params_wrapper.rb: 207:in process_action’
….2.21/lib/active_record/railties/controller_runtime.rb: 18:in process_action' …gems/actionpack-3.2.21/lib/abstract_controller/base.rb: 121:in process’
…actionpack-3.2.21/lib/abstract_controller/rendering.rb: 45:in process' …/gems/actionpack-3.2.21/lib/action_controller/metal.rb: 203:in dispatch’
…-3.2.21/lib/action_controller/metal/rack_delegation.rb: 14:in dispatch' …/gems/actionpack-3.2.21/lib/action_controller/metal.rb: 246:in block in action’
…onpack-3.2.21/lib/action_dispatch/routing/route_set.rb: 73:in call' …onpack-3.2.21/lib/action_dispatch/routing/route_set.rb: 73:in dispatch’
…onpack-3.2.21/lib/action_dispatch/routing/route_set.rb: 36:in call' …le/ruby/2.1.0/gems/journey-1.0.4/lib/journey/router.rb: 68:in block in call’
…le/ruby/2.1.0/gems/journey-1.0.4/lib/journey/router.rb: 56:in each' …le/ruby/2.1.0/gems/journey-1.0.4/lib/journey/router.rb: 56:in call’
…onpack-3.2.21/lib/action_dispatch/routing/route_set.rb: 608:in call' …uby/2.1.0/gems/omniauth-1.0.3/lib/omniauth/strategy.rb: 168:in call!’
…uby/2.1.0/gems/omniauth-1.0.3/lib/omniauth/strategy.rb: 148:in call' …uby/2.1.0/gems/omniauth-1.0.3/lib/omniauth/strategy.rb: 168:in call!’
…uby/2.1.0/gems/omniauth-1.0.3/lib/omniauth/strategy.rb: 148:in call' …ruby/2.1.0/gems/omniauth-1.0.3/lib/omniauth/builder.rb: 42:in call’
…dle/ruby/2.1.0/gems/sass-3.2.9/lib/sass/plugin/rack.rb: 54:in call' …by/2.1.0/gems/rack-cache-1.2/lib/rack/cache/context.rb: 136:in forward’
…by/2.1.0/gems/rack-cache-1.2/lib/rack/cache/context.rb: 245:in fetch' …by/2.1.0/gems/rack-cache-1.2/lib/rack/cache/context.rb: 185:in lookup’
…by/2.1.0/gems/rack-cache-1.2/lib/rack/cache/context.rb: 66:in call!' …by/2.1.0/gems/rack-cache-1.2/lib/rack/cache/context.rb: 51:in call’
…dle/ruby/2.1.0/gems/warden-1.1.1/lib/warden/manager.rb: 35:in block in call' …dle/ruby/2.1.0/gems/warden-1.1.1/lib/warden/manager.rb: 34:in catch’
…dle/ruby/2.1.0/gems/warden-1.1.1/lib/warden/manager.rb: 34:in call' …b/action_dispatch/middleware/best_standards_support.rb: 17:in call’
…dor/bundle/ruby/2.1.0/gems/rack-1.4.5/lib/rack/etag.rb: 23:in call' …/ruby/2.1.0/gems/rack-1.4.5/lib/rack/conditionalget.rb: 25:in call’
…tionpack-3.2.21/lib/action_dispatch/middleware/head.rb: 14:in call' …3.2.21/lib/action_dispatch/middleware/params_parser.rb: 21:in call’
…ionpack-3.2.21/lib/action_dispatch/middleware/flash.rb: 242:in call' …/2.1.0/gems/rack-1.4.5/lib/rack/session/abstract/id.rb: 210:in context’
…/2.1.0/gems/rack-1.4.5/lib/rack/session/abstract/id.rb: 205:in call' …npack-3.2.21/lib/action_dispatch/middleware/cookies.rb: 341:in call’
…s/activerecord-3.2.21/lib/active_record/query_cache.rb: 64:in call' …record/connection_adapters/abstract/connection_pool.rb: 479:in call’
…ack-3.2.21/lib/action_dispatch/middleware/callbacks.rb: 28:in block in call' …s/activesupport-3.2.21/lib/active_support/callbacks.rb: 405:in _run__2305709260636702136__call__3264484816793770857__callbacks’
…s/activesupport-3.2.21/lib/active_support/callbacks.rb: 405:in __run_callback' …s/activesupport-3.2.21/lib/active_support/callbacks.rb: 385:in _run_call_callbacks’
…s/activesupport-3.2.21/lib/active_support/callbacks.rb: 81:in run_callbacks' …ack-3.2.21/lib/action_dispatch/middleware/callbacks.rb: 27:in call’
…ack-3.2.21/lib/action_dispatch/middleware/remote_ip.rb: 31:in call' …0/gems/airbrake-4.1.0/lib/airbrake/rails/middleware.rb: 13:in call’
….21/lib/action_dispatch/middleware/debug_exceptions.rb: 16:in call' …2.21/lib/action_dispatch/middleware/show_exceptions.rb: 56:in call’
…by/2.1.0/gems/railties-3.2.21/lib/rails/rack/logger.rb: 32:in call_app' …by/2.1.0/gems/railties-3.2.21/lib/rails/rack/logger.rb: 16:in block in call’
…ivesupport-3.2.21/lib/active_support/tagged_logging.rb: 22:in tagged' …by/2.1.0/gems/railties-3.2.21/lib/rails/rack/logger.rb: 16:in call’

``

We also get these errors on heroku from time to time. I wish I knew what was causing them. A restart always solves the problem.

N.