rails-on-services/apartment

Rails 7 compatibility issue

archonic opened this issue · 3 comments

Steps to reproduce

Hit this error while upgrading to Rails 7. Seen on my main app, don't have a reproduction app yet. This is getting an uploaded avatar. The URL was generated with url_for( resource.avatar.variant(resize_to_limit: [100,100]) ).

Expected behavior

ActiveStorage varient URLs should not 500

Actual behavior

ActiveStorage variant URLs are 500'ing with:

web_1            | Completed 500 Internal Server Error in 75ms (ActiveRecord: 0.5ms | Allocations: 2178)
web_1            |
web_1            |
web_1            |
web_1            | ArgumentError (unknown keyword: :database):
web_1            |
web_1            | activerecord (7.0.1) lib/active_record/connection_handling.rb:137:in `connected_to'
web_1            | apartment (fefed666e48f) lib/apartment/active_record/connection_handling.rb:11:in `connected_to_with_tenant'
web_1            | activestorage (7.0.1) app/models/active_storage/variant_with_record.rb:44:in `create_or_find_record'
web_1            | activestorage (7.0.1) app/models/active_storage/variant_with_record.rb:19:in `block in process'
web_1            | activestorage (7.0.1) app/models/active_storage/variant_with_record.rb:36:in `block (2 levels) in transform_blob'
web_1            | activestorage (7.0.1) lib/active_storage/transformers/transformer.rb:25:in `transform'
web_1            | activestorage (7.0.1) app/models/active_storage/variation.rb:56:in `block in transform'
web_1            | activesupport (7.0.1) lib/active_support/notifications.rb:208:in `instrument'
web_1            | activestorage (7.0.1) app/models/active_storage/variation.rb:55:in `transform'
web_1            | activestorage (7.0.1) app/models/active_storage/variant_with_record.rb:35:in `block in transform_blob'
web_1            | activestorage (7.0.1) lib/active_storage/downloader.rb:15:in `block in open'
web_1            | activestorage (7.0.1) lib/active_storage/downloader.rb:24:in `open_tempfile'
web_1            | activestorage (7.0.1) lib/active_storage/downloader.rb:12:in `open'
web_1            | activestorage (7.0.1) lib/active_storage/service.rb:90:in `open'
web_1            | activestorage (7.0.1) app/models/active_storage/blob.rb:301:in `open'
web_1            | activestorage (7.0.1) app/models/active_storage/variant_with_record.rb:34:in `transform_blob'
web_1            | activestorage (7.0.1) app/models/active_storage/variant_with_record.rb:19:in `process'
web_1            | activestorage (7.0.1) app/models/active_storage/variant_with_record.rb:14:in `processed'
web_1            | activestorage (7.0.1) app/controllers/active_storage/representations/base_controller.rb:14:in `set_representation'
web_1            | activesupport (7.0.1) lib/active_support/callbacks.rb:400:in `block in make_lambda'
web_1            | activesupport (7.0.1) lib/active_support/callbacks.rb:199:in `block (2 levels) in halting'
web_1            | actionpack (7.0.1) lib/abstract_controller/callbacks.rb:34:in `block (2 levels) in <module:Callbacks>'
web_1            | activesupport (7.0.1) lib/active_support/callbacks.rb:200:in `block in halting'
web_1            | activesupport (7.0.1) lib/active_support/callbacks.rb:595:in `block in invoke_before'
web_1            | activesupport (7.0.1) lib/active_support/callbacks.rb:595:in `each'
web_1            | activesupport (7.0.1) lib/active_support/callbacks.rb:595:in `invoke_before'
web_1            | activesupport (7.0.1) lib/active_support/callbacks.rb:116:in `block in run_callbacks'
web_1            | ahoy_matey (3.0.5) lib/ahoy/controller.rb:45:in `set_ahoy_request_store'
web_1            | activesupport (7.0.1) lib/active_support/callbacks.rb:127:in `block in run_callbacks'
web_1            | actiontext (7.0.1) lib/action_text/rendering.rb:20:in `with_renderer'
web_1            | actiontext (7.0.1) lib/action_text/engine.rb:69:in `block (4 levels) in <class:Engine>'
web_1            | activesupport (7.0.1) lib/active_support/callbacks.rb:127:in `instance_exec'
web_1            | activesupport (7.0.1) lib/active_support/callbacks.rb:127:in `block in run_callbacks'
web_1            | activesupport (7.0.1) lib/active_support/callbacks.rb:138:in `run_callbacks'
web_1            | actionpack (7.0.1) lib/abstract_controller/callbacks.rb:233:in `process_action'
web_1            | actionpack (7.0.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
web_1            | actionpack (7.0.1) lib/action_controller/metal/instrumentation.rb:67:in `block in process_action'
web_1            | activesupport (7.0.1) lib/active_support/notifications.rb:206:in `block in instrument'
web_1            | activesupport (7.0.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
web_1            | activesupport (7.0.1) lib/active_support/notifications.rb:206:in `instrument'
web_1            | actionpack (7.0.1) lib/action_controller/metal/instrumentation.rb:66:in `process_action'
web_1            | actionpack (7.0.1) lib/action_controller/metal/params_wrapper.rb:259:in `process_action'
web_1            | searchkick (4.6.2) lib/searchkick/logging.rb:212:in `process_action'
web_1            | activerecord (7.0.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
web_1            | actionpack (7.0.1) lib/abstract_controller/base.rb:151:in `process'
web_1            | actionview (7.0.1) lib/action_view/rendering.rb:39:in `process'
web_1            | actionpack (7.0.1) lib/action_controller/metal/live.rb:266:in `block (2 levels) in process'
web_1            | activesupport (7.0.1) lib/active_support/concurrency/share_lock.rb:162:in `sharing'
web_1            | activesupport (7.0.1) lib/active_support/dependencies/interlock.rb:37:in `running'
web_1            | actionpack (7.0.1) lib/action_controller/metal/live.rb:258:in `block in process'
web_1            | actionpack (7.0.1) lib/action_controller/metal/live.rb:343:in `block in new_controller_thread'

System configuration

Rails 7.0.2, Ruby 3.0.3

  • Database: (Tell us what database and its version you use.)

Postgres

  • Apartment version:

2.11.0

  • Apartment config (in config/initializers/apartment.rb or so):

ActiveStorage tables are tenanted.

  • use_schemas: (true or false)
    true

It looks as if this alias is failing to override ActiveRecord:
https://github.com/rails-on-services/apartment/blob/development/lib/apartment/active_record/connection_handling.rb#L18

I'm not sure if it's related, but I noticed in the Rails 7 upgrade that a dynamically defined boolean attribute method example? was instead running a model method example(argument).

This is caused by the removed database: keyword in Rails 7. I submitted a PR to fix it (#194).
Worth nothing: This isn't directly related to ActiveStorage, it occurs whenever connected_to is called.

The above issue was addressed by the PR mentioned so I'll close this issue. There are still Rails 7 incompatibilities related to ActiveStorage however (#196 )

We have the same concern as archonic and we want to know when you plan to do a new tag for the gem?