Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no implicit conversion of ActiveRecord::Reflection::HasManyReflection into Array #170

Closed
rpbaltazar opened this issue Sep 12, 2021 · 2 comments

Comments

@rpbaltazar
Copy link
Contributor

rpbaltazar commented Sep 12, 2021

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
Copy link
Contributor Author

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
Copy link
Contributor Author

This only happens in cases where we include the apartment model concern, which is not documented

rpbaltazar added a commit that referenced this issue Sep 13, 2021
**Implemented enhancements:**

- #112 - Allow a list of schemas when switching using schemas - #154
- Create schema between different versions of DB - #155 

**Fixed bugs:**

- #170 - Cache Key breaks on rails 6.0.4 - #171 

**Closed issues:**

- Add ruby 3 to the build matrix - #162 
- update rubocop and fixed broken rules - #157 
- added junit formatter and saving test output in circle - #172
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant