no implicit conversion of ActiveRecord::Reflection::HasManyReflection into Array
rpbaltazar opened this issue · 2 comments
rpbaltazar commented
Steps to reproduce
While running rspec and factories creation, this error would occur.
An error occurred while loading ./spec/requests/dash/v4/catalog_spec.rb.
Failure/Error: catalog.reward_campaigns = create_list(:reward_campaign, evaluator.create_with_rewards)
TypeError:
no implicit conversion of ActiveRecord::Reflection::HasManyReflection into Array
# /usr/local/bundle/gems/ros-apartment-2.9.0/lib/apartment/model.rb:20:in `+'
# /usr/local/bundle/gems/ros-apartment-2.9.0/lib/apartment/model.rb:20:in `cached_find_by_statement'
# ./spec/factories/catalogs.rb:18:in `block (3 levels) in <main>'
# /usr/local/bundle/gems/factory_bot-6.1.0/lib/factory_bot/callback.rb:13:in `instance_exec'
# /usr/local/bundle/gems/factory_bot-6.1.0/lib/factory_bot/callback.rb:13:in `run'
# /usr/local/bundle/gems/factory_bot-6.1.0/lib/factory_bot/callbacks_observer.rb:11:in `block in update'
# /usr/local/bundle/gems/factory_bot-6.1.0/lib/factory_bot/callbacks_observer.rb:10:in `each'
# /usr/local/bundle/gems/factory_bot-6.1.0/lib/factory_bot/callbacks_observer.rb:10:in `update'
# /usr/local/bundle/gems/factory_bot-6.1.0/lib/factory_bot/evaluation.rb:24:in `notify'
# /usr/local/bundle/gems/factory_bot-6.1.0/lib/factory_bot/strategy/create.rb:13:in `block in result'
# /usr/local/bundle/gems/factory_bot-6.1.0/lib/factory_bot/strategy/create.rb:9:in `tap'
# /usr/local/bundle/gems/factory_bot-6.1.0/lib/factory_bot/strategy/create.rb:9:in `result'
# /usr/local/bundle/gems/factory_bot-6.1.0/lib/factory_bot/factory.rb:43:in `run'
# /usr/local/bundle/gems/factory_bot-6.1.0/lib/factory_bot/factory_runner.rb:29:in `block in run'
# /usr/local/bundle/gems/factory_bot-6.1.0/lib/factory_bot/factory_runner.rb:28:in `run'
# /usr/local/bundle/gems/factory_bot-6.1.0/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
# ./spec/support/shared_examples/object_level_permissions/filter_by_acl.rb:49:in `block (3 levels) in <top (required)>'
# ./spec/support/shared_examples/object_level_permissions/filter_by_acl.rb:41:in `each'
# ./spec/support/shared_examples/object_level_permissions/filter_by_acl.rb:41:in `block (2 levels) in <top (required)>'
# ./spec/support/shared_examples/object_level_permissions/filter_by_acl.rb:36:in `block in <top (required)>'
# ./spec/requests/dash/v4/catalog_spec.rb:289:in `block (4 levels) in <main>'
# ./spec/requests/dash/v4/catalog_spec.rb:288:in `block (3 levels) in <main>'
# ./spec/requests/dash/v4/catalog_spec.rb:287:in `block (2 levels) in <main>'
# ./spec/requests/dash/v4/catalog_spec.rb:69:in `block in <main>'
# ./spec/requests/dash/v4/catalog_spec.rb:8:in `<main>'
# /usr/local/bundle/gems/bootsnap-1.7.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
# /usr/local/bundle/gems/bootsnap-1.7.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
Expected behavior
No errors thrown
Actual behavior
Unhandled exception
System configuration
-
Database: (Tell us what database and its version you use.)
-
Apartment version:
2.9.0
-
Apartment config (in
config/initializers/apartment.rb
or so):use_schemas
:true
-
Rails (or ActiveRecord) version:
6.0.4.1
- Ruby version:
2.7.3
rpbaltazar commented
After some investigation, seems like with rails 6.0.4 (this was not happening with rails 6.0.3), the method cached_find_by_statement
started receiving an object ActiveRecord::Reflection::BelongsToReflection as the key, which wouldn't work with an array.
rpbaltazar commented
This only happens in cases where we include the apartment model concern, which is not documented