Firstly - thanks for a gem of a gem :)
I have
config.require_tenant = true
My test model has an active storage attachment:
class Test < ApplicationRecord
acts_as_tenant :account
has_one_attached :video
end
I should be able to view a representation for this blob using:
<% blob = test.video.blob %>
<% if blob.representable? %>
<%= image_tag url_for(blob.representation(resize_to_limit: [ 800, 600 ] )) %>
<% end %>
This generates a link to the representations redirect controller. In my case:
http://localhost:3000/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--bb17c469cc67487b1cd754e16f430df53d63f650/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VY21WemFYcGxYM1J2WDJ4cGJXbDBXd2RwQWdBRWFRSUFBdz09IiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--b0ad9c958551b563ac36c2b25326c7e8112efc91/1min.mp4
This is a rails controller accessing an active storage attachment (which isn't scoped to an account), so I wouldn't expect it to trigger an ActsAsTenant error - however, I get
ActsAsTenant::Errors::NoTenantSet in ActiveStorage::Representations::RedirectController#show
Full stack is copied below. I think this is triggered by the attempt to touch attachment records after creating a variant
Technically, I suppose this is a correct catch by ActsAsTenant, but practically speaking, it's not what I would expect to happen, and an unexpected breakage in Rails behaviour.
I have a simple demonstration project if that would help.
Thoughts?
Full Stack
`
19:20:11 web.1 | ActsAsTenant::Errors::NoTenantSet (ActsAsTenant::Errors::NoTenantSet):
19:20:11 web.1 |
19:20:11 web.1 | acts_as_tenant (1.0.1) lib/acts_as_tenant/model_extensions.rb:21:in `block in acts_as_tenant'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/scoping/default.rb:163:in `instance_exec'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/scoping/default.rb:163:in `block (2 levels) in build_default_scope'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/scoping/default.rb:159:in `each'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/scoping/default.rb:159:in `inject'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/scoping/default.rb:159:in `block in build_default_scope'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/scoping/default.rb:197:in `evaluate_default_scope'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/scoping/default.rb:158:in `build_default_scope'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/scoping/named.rb:46:in `default_scoped'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/scoping/named.rb:40:in `scope_for_association'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/associations/preloader/association.rb:291:in `build_scope'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/associations/preloader/association.rb:182:in `scope'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/associations/preloader/association.rb:163:in `loader_query'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/associations/preloader/batch.rb:41:in `each'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/associations/preloader/batch.rb:41:in `group_by'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/associations/preloader/batch.rb:41:in `group_and_load_similar'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/associations/preloader/batch.rb:27:in `call'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/associations/preloader.rb:121:in `call'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/relation.rb:867:in `block in preload_associations'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/relation.rb:866:in `each'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/relation.rb:866:in `preload_associations'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/relation.rb:951:in `block in exec_queries'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/relation.rb:1003:in `skip_query_cache_if_necessary'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/relation.rb:941:in `exec_queries'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/association_relation.rb:44:in `exec_queries'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/relation.rb:727:in `load'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/relation.rb:264:in `records'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/relation/delegation.rb:100:in `each'
19:20:11 web.1 | activestorage (7.1.2) app/models/active_storage/blob.rb:380:in `touch_attachment_records'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:403:in `block in make_lambda'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:239:in `block in halting_and_conditional'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:602:in `block in invoke_after'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:602:in `each'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:602:in `invoke_after'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:111:in `run_callbacks'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:952:in `_run_update_callbacks'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/callbacks.rb:449:in `_update_record'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/timestamp.rb:120:in `_update_record'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/persistence.rb:1220:in `create_or_update'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/callbacks.rb:441:in `block in create_or_update'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:121:in `block in run_callbacks'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/autosave_association.rb:375:in `around_save_collection_association'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:130:in `block in run_callbacks'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:141:in `run_callbacks'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:952:in `_run_save_callbacks'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/callbacks.rb:441:in `create_or_update'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/timestamp.rb:125:in `create_or_update'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/persistence.rb:718:in `save'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/validations.rb:49:in `save'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/transactions.rb:309:in `block in save'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/transactions.rb:365:in `block in with_transaction_returning_status'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/connection_adapters/abstract/transaction.rb:535:in `block in within_new_transaction'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/concurrency/null_lock.rb:9:in `synchronize'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/connection_adapters/abstract/transaction.rb:532:in `within_new_transaction'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/connection_adapters/abstract/database_statements.rb:344:in `transaction'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/transactions.rb:361:in `with_transaction_returning_status'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/transactions.rb:309:in `save'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/suppressor.rb:52:in `save'
19:20:11 web.1 | activestorage (7.1.2) lib/active_storage/attached/one.rb:61:in `attach'
19:20:11 web.1 | activestorage (7.1.2) app/models/active_storage/preview.rb:101:in `block (2 levels) in process'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/connection_handling.rb:361:in `with_role_and_shard'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/connection_handling.rb:147:in `connected_to'
19:20:11 web.1 | activestorage (7.1.2) app/models/active_storage/preview.rb:100:in `block in process'
19:20:11 web.1 | activestorage (7.1.2) lib/active_storage/previewer/video_previewer.rb:26:in `block (2 levels) in preview'
19:20:11 web.1 | activestorage (7.1.2) lib/active_storage/previewer.rb:55:in `block in draw'
19:20:11 web.1 | activestorage (7.1.2) lib/active_storage/previewer.rb:63:in `open_tempfile'
19:20:11 web.1 | activestorage (7.1.2) lib/active_storage/previewer.rb:50:in `draw'
19:20:11 web.1 | activestorage (7.1.2) lib/active_storage/previewer/video_previewer.rb:33:in `draw_relevant_frame_from'
19:20:11 web.1 | activestorage (7.1.2) lib/active_storage/previewer/video_previewer.rb:25:in `block in preview'
19:20:11 web.1 | activestorage (7.1.2) lib/active_storage/downloader.rb:15:in `block in open'
19:20:11 web.1 | activestorage (7.1.2) lib/active_storage/downloader.rb:24:in `open_tempfile'
19:20:11 web.1 | activestorage (7.1.2) lib/active_storage/downloader.rb:12:in `open'
19:20:11 web.1 | activestorage (7.1.2) lib/active_storage/service.rb:92:in `open'
19:20:11 web.1 | activestorage (7.1.2) app/models/active_storage/blob.rb:298:in `open'
19:20:11 web.1 | activestorage (7.1.2) lib/active_storage/previewer.rb:32:in `download_blob_to_tempfile'
19:20:11 web.1 | activestorage (7.1.2) lib/active_storage/previewer/video_previewer.rb:24:in `preview'
19:20:11 web.1 | activestorage (7.1.2) app/models/active_storage/preview.rb:99:in `process'
19:20:11 web.1 | activestorage (7.1.2) app/models/active_storage/preview.rb:49:in `processed'
19:20:11 web.1 | activestorage (7.1.2) app/controllers/active_storage/representations/base_controller.rb:14:in `set_representation'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:403:in `block in make_lambda'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:202:in `block (2 levels) in halting'
19:20:11 web.1 | actionpack (7.1.2) lib/abstract_controller/callbacks.rb:34:in `block (2 levels) in '
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:203:in `block in halting'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:598:in `block in invoke_before'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:598:in `each'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:598:in `invoke_before'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:119:in `block in run_callbacks'
19:20:11 web.1 | actiontext (7.1.2) lib/action_text/rendering.rb:23:in `with_renderer'
19:20:11 web.1 | actiontext (7.1.2) lib/action_text/engine.rb:69:in `block (4 levels) in '
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:130:in `instance_exec'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:130:in `block in run_callbacks'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:141:in `run_callbacks'
19:20:11 web.1 | actionpack (7.1.2) lib/abstract_controller/callbacks.rb:258:in `process_action'
19:20:11 web.1 | actionpack (7.1.2) lib/action_controller/metal/rescue.rb:25:in `process_action'
19:20:11 web.1 | actionpack (7.1.2) lib/action_controller/metal/instrumentation.rb:74:in `block in process_action'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/notifications.rb:206:in `block in instrument'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/notifications/instrumenter.rb:58:in `instrument'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/notifications.rb:206:in `instrument'
19:20:11 web.1 | actionpack (7.1.2) lib/action_controller/metal/instrumentation.rb:73:in `process_action'
19:20:11 web.1 | actionpack (7.1.2) lib/action_controller/metal/params_wrapper.rb:261:in `process_action'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/railties/controller_runtime.rb:32:in `process_action'
19:20:11 web.1 | actionpack (7.1.2) lib/abstract_controller/base.rb:160:in `process'
19:20:11 web.1 | actionview (7.1.2) lib/action_view/rendering.rb:40:in `process'
19:20:11 web.1 | actionpack (7.1.2) lib/action_controller/metal.rb:227:in `dispatch'
19:20:11 web.1 | actionpack (7.1.2) lib/action_controller/metal.rb:309:in `dispatch'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/routing/route_set.rb:32:in `serve'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/journey/router.rb:51:in `block in serve'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/journey/router.rb:131:in `block in find_routes'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/journey/router.rb:124:in `each'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/journey/router.rb:124:in `find_routes'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/journey/router.rb:32:in `serve'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/routing/route_set.rb:882:in `call'
19:20:11 web.1 | rack (3.0.8) lib/rack/tempfile_reaper.rb:20:in `call'
19:20:11 web.1 | rack (3.0.8) lib/rack/etag.rb:29:in `call'
19:20:11 web.1 | rack (3.0.8) lib/rack/conditional_get.rb:31:in `call'
19:20:11 web.1 | rack (3.0.8) lib/rack/head.rb:15:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/http/permissions_policy.rb:36:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/http/content_security_policy.rb:33:in `call'
19:20:11 web.1 | rack-session (2.0.0) lib/rack/session/abstract/id.rb:272:in `context'
19:20:11 web.1 | rack-session (2.0.0) lib/rack/session/abstract/id.rb:266:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/cookies.rb:689:in `call'
19:20:11 web.1 | activerecord (7.1.2) lib/active_record/migration.rb:654:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/callbacks.rb:101:in `run_callbacks'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/actionable_exceptions.rb:16:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
19:20:11 web.1 | web-console (4.2.1) lib/web_console/middleware.rb:132:in `call_app'
19:20:11 web.1 | web-console (4.2.1) lib/web_console/middleware.rb:28:in `block in call'
19:20:11 web.1 | web-console (4.2.1) lib/web_console/middleware.rb:17:in `catch'
19:20:11 web.1 | web-console (4.2.1) lib/web_console/middleware.rb:17:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
19:20:11 web.1 | railties (7.1.2) lib/rails/rack/logger.rb:37:in `call_app'
19:20:11 web.1 | railties (7.1.2) lib/rails/rack/logger.rb:24:in `block in call'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/tagged_logging.rb:135:in `block in tagged'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/tagged_logging.rb:39:in `tagged'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/tagged_logging.rb:135:in `tagged'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/broadcast_logger.rb:240:in `method_missing'
19:20:11 web.1 | railties (7.1.2) lib/rails/rack/logger.rb:24:in `call'
19:20:11 web.1 | sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/remote_ip.rb:92:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/request_id.rb:28:in `call'
19:20:11 web.1 | rack (3.0.8) lib/rack/method_override.rb:28:in `call'
19:20:11 web.1 | rack (3.0.8) lib/rack/runtime.rb:24:in `call'
19:20:11 web.1 | activesupport (7.1.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/server_timing.rb:59:in `block in call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/server_timing.rb:24:in `collect_events'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/server_timing.rb:58:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/static.rb:25:in `call'
19:20:11 web.1 | rack (3.0.8) lib/rack/sendfile.rb:114:in `call'
19:20:11 web.1 | actionpack (7.1.2) lib/action_dispatch/middleware/host_authorization.rb:141:in `call'
19:20:11 web.1 | railties (7.1.2) lib/rails/engine.rb:529:in `call'
19:20:11 web.1 | puma (6.4.0) lib/puma/configuration.rb:272:in `call'
19:20:11 web.1 | puma (6.4.0) lib/puma/request.rb:100:in `block in handle_request'
19:20:11 web.1 | puma (6.4.0) lib/puma/thread_pool.rb:378:in `with_force_shutdown'
19:20:11 web.1 | puma (6.4.0) lib/puma/request.rb:99:in `handle_request'
19:20:11 web.1 | puma (6.4.0) lib/puma/server.rb:443:in `process_client'
19:20:11 web.1 | puma (6.4.0) lib/puma/server.rb:241:in `block in run'
19:20:11 web.1 | puma (6.4.0) lib/puma/thread_pool.rb:155:in `block in spawn_thread'
`