shrinerb / shrine

File Attachment toolkit for Ruby applications
https://shrinerb.com
MIT License
3.18k stars 275 forks source link

[Bug]: NoMethodError (undefined method 'bucket' for nil:NilClass) #627

Closed masudhossain closed 1 year ago

masudhossain commented 1 year ago

Report

Recently got this error after upgrading to Rails 6 from 5.0.2 and ruby 3.0.3

Expected Behavior

I expected to upload properly like it did before.

Actual Behavior

Threw this error below

Started GET "/s3/multipart/2~Ns6N_ZFKITU5lkiXZcYXzu4VH5QJbXn?key=cache%2F866e5c6546bebdbc7feb0f264dd941b6.png" for 71.44.217.115 at 2023-04-06 20:50:48 -0400
Started GET "/s3/multipart/2~Ns6N_ZFKITU5lkiXZcYXzu4VH5QJbXn/1?key=cache%2F866e5c6546bebdbc7feb0f264dd941b6.png" for 71.44.217.115 at 2023-04-06 20:50:50 -0400

NoMethodError (undefined method `bucket' for nil:NilClass):

aws-sdk-s3 (1.120.1) lib/aws-sdk-s3/endpoint_provider.rb:13:in `resolve_endpoint'
aws-sdk-s3 (1.120.1) lib/aws-sdk-s3/plugins/endpoints.rb:31:in `call'
aws-sdk-core (3.171.0) lib/seahorse/client/plugins/endpoint.rb:47:in `call'
aws-sdk-core (3.171.0) lib/aws-sdk-core/plugins/param_validator.rb:26:in `call'
aws-sdk-core (3.171.0) lib/seahorse/client/plugins/raise_response_errors.rb:16:in `call'
aws-sdk-s3 (1.120.1) lib/aws-sdk-s3/plugins/sse_cpk.rb:24:in `call'
aws-sdk-s3 (1.120.1) lib/aws-sdk-s3/plugins/dualstack.rb:21:in `call'
aws-sdk-s3 (1.120.1) lib/aws-sdk-s3/plugins/accelerate.rb:43:in `call'
aws-sdk-core (3.171.0) lib/aws-sdk-core/plugins/checksum_algorithm.rb:111:in `call'
aws-sdk-core (3.171.0) lib/aws-sdk-core/plugins/jsonvalue_converter.rb:16:in `call'
aws-sdk-core (3.171.0) lib/aws-sdk-core/plugins/idempotency_token.rb:19:in `call'
aws-sdk-core (3.171.0) lib/aws-sdk-core/plugins/param_converter.rb:26:in `call'
aws-sdk-core (3.171.0) lib/seahorse/client/plugins/request_callback.rb:71:in `call'
aws-sdk-core (3.171.0) lib/aws-sdk-core/plugins/response_paging.rb:12:in `call'
aws-sdk-core (3.171.0) lib/seahorse/client/plugins/response_target.rb:24:in `call'
aws-sdk-s3 (1.120.1) lib/aws-sdk-s3/presigner.rb:185:in `block in handle_presigned_url_context'
aws-sdk-core (3.171.0) lib/seahorse/client/request.rb:72:in `send_request'
aws-sdk-s3 (1.120.1) lib/aws-sdk-s3/presigner.rb:146:in `_presigned_request'
aws-sdk-s3 (1.120.1) lib/aws-sdk-s3/presigner.rb:78:in `presigned_url'
uppy-s3_multipart (0.3.4) lib/uppy/s3_multipart/client.rb:28:in `prepare_upload_part'
uppy-s3_multipart (0.3.4) lib/uppy/s3_multipart/app.rb:120:in `client_call'
uppy-s3_multipart (0.3.4) lib/uppy/s3_multipart/app.rb:77:in `block (2 levels) in <class:Router>'
roda (3.66.0) lib/roda/request.rb:603:in `if_match'
roda (3.66.0) lib/roda/request.rb:530:in `_verb'
roda (3.66.0) lib/roda/request.rb:104:in `get'
uppy-s3_multipart (0.3.4) lib/uppy/s3_multipart/app.rb:74:in `block in <class:Router>'
roda (3.66.0) lib/roda.rb:518:in `_roda_run_main_route'
roda (3.66.0) lib/roda.rb:496:in `block in _roda_handle_main_route'
roda (3.66.0) lib/roda.rb:494:in `catch'
roda (3.66.0) lib/roda.rb:494:in `_roda_handle_main_route'
roda (3.66.0) lib/roda.rb:380:in `block in base_rack_app_callable'
roda (3.66.0) lib/roda.rb:53:in `call'
uppy-s3_multipart (0.3.4) lib/uppy/s3_multipart/app.rb:20:in `call'
actionpack (6.1.7.3) lib/action_dispatch/routing/mapper.rb:20:in `block in <class:Constraints>'
actionpack (6.1.7.3) lib/action_dispatch/routing/mapper.rb:49:in `serve'
actionpack (6.1.7.3) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (6.1.7.3) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.1.7.3) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.1.7.3) lib/action_dispatch/routing/route_set.rb:842:in `call'
rack-attack (6.6.1) lib/rack/attack.rb:127:in `call'
omniauth (1.9.2) lib/omniauth/strategy.rb:192:in `call!'
omniauth (1.9.2) lib/omniauth/strategy.rb:169:in `call'
omniauth (1.9.2) lib/omniauth/builder.rb:45:in `call'
omniauth (1.9.2) lib/omniauth/strategy.rb:192:in `call!'
omniauth (1.9.2) lib/omniauth/strategy.rb:169:in `call'
omniauth (1.9.2) lib/omniauth/strategy.rb:192:in `call!'
omniauth (1.9.2) lib/omniauth/strategy.rb:169:in `call'
omniauth (1.9.2) lib/omniauth/strategy.rb:192:in `call!'
omniauth (1.9.2) lib/omniauth/strategy.rb:169:in `call'
omniauth (1.9.2) lib/omniauth/strategy.rb:192:in `call!'
omniauth (1.9.2) lib/omniauth/strategy.rb:169:in `call'
omniauth (1.9.2) lib/omniauth/strategy.rb:192:in `call!'
omniauth (1.9.2) lib/omniauth/strategy.rb:169:in `call'
omniauth (1.9.2) lib/omniauth/strategy.rb:192:in `call!'
omniauth (1.9.2) lib/omniauth/strategy.rb:169:in `call'
omniauth (1.9.2) lib/omniauth/builder.rb:45:in `call'
htmlcompressor (0.4.0) lib/htmlcompressor/rack.rb:36:in `call'
rack (2.2.6.4) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.6.4) lib/rack/etag.rb:27:in `call'
rack (2.2.6.4) lib/rack/conditional_get.rb:27:in `call'
rack (2.2.6.4) lib/rack/head.rb:12:in `call'
actionpack (6.1.7.3) lib/action_dispatch/http/permissions_policy.rb:22:in `call'
actionpack (6.1.7.3) lib/action_dispatch/http/content_security_policy.rb:19:in `call'
rack (2.2.6.4) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.6.4) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (6.1.7.3) lib/action_dispatch/middleware/cookies.rb:697:in `call'
activerecord (6.1.7.3) lib/active_record/migration.rb:601:in `call'
actionpack (6.1.7.3) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.1.7.3) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (6.1.7.3) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.1.7.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.1.7.3) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
rollbar (3.4.0) lib/rollbar/middleware/rails/rollbar.rb:25:in `block in call'
rollbar (3.4.0) lib/rollbar.rb:145:in `scoped'
rollbar (3.4.0) lib/rollbar/middleware/rails/rollbar.rb:22:in `call'
appsignal (3.4.0) lib/appsignal/rack/rails_instrumentation.rb:32:in `call_with_appsignal_monitoring'
appsignal (3.4.0) lib/appsignal/rack/rails_instrumentation.rb:17:in `call'
actionpack (6.1.7.3) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
rollbar (3.4.0) lib/rollbar/middleware/rails/show_exceptions.rb:22:in `call_with_rollbar'
web-console (4.2.0) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.2.0) lib/web_console/middleware.rb:19:in `block in call'
web-console (4.2.0) lib/web_console/middleware.rb:17:in `catch'
web-console (4.2.0) lib/web_console/middleware.rb:17:in `call'
actionpack (6.1.7.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.1.7.3) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.1.7.3) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.1.7.3) lib/active_support/tagged_logging.rb:99:in `block in tagged'
activesupport (6.1.7.3) lib/active_support/tagged_logging.rb:37:in `tagged'
activesupport (6.1.7.3) lib/active_support/tagged_logging.rb:99:in `tagged'
railties (6.1.7.3) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.1.7.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
request_store (1.5.1) lib/request_store/middleware.rb:19:in `call'
actionpack (6.1.7.3) lib/action_dispatch/middleware/request_id.rb:26:in `call'
rack (2.2.6.4) lib/rack/method_override.rb:24:in `call'
rack (2.2.6.4) lib/rack/runtime.rb:22:in `call'
activesupport (6.1.7.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.1.7.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.1.7.3) lib/action_dispatch/middleware/static.rb:24:in `call'
rack (2.2.6.4) lib/rack/sendfile.rb:110:in `call'
actionpack (6.1.7.3) lib/action_dispatch/middleware/host_authorization.rb:148:in `call'
webpacker (3.2.2) lib/webpacker/dev_server_proxy.rb:18:in `perform_request'
rack-proxy (0.7.6) lib/rack/proxy.rb:87:in `call'
railties (6.1.7.3) lib/rails/engine.rb:539:in `call'
puma (5.3.2) lib/puma/configuration.rb:249:in `call'
puma (5.3.2) lib/puma/request.rb:77:in `block in handle_request'
puma (5.3.2) lib/puma/thread_pool.rb:338:in `with_force_shutdown'
puma (5.3.2) lib/puma/request.rb:76:in `handle_request'
puma (5.3.2) lib/puma/server.rb:438:in `process_client'
puma (5.3.2) lib/puma/thread_pool.rb:145:in `block in spawn_thread'

Steps to Reproduce the Problem

  1. Rails 6, ruby 3.0.3
  2. Shrine.rb
    
    require "shrine/storage/s3"

s3_options = { bucket: Rails.application.secrets.digitalocean_spaces_bucket, access_key_id: Rails.application.secrets.digitalocean_spaces_key, secret_access_key: Rails.application.secrets.digitalocean_spaces_secret, region: Rails.application.secrets.digitalocean_spaces_region, endpoint: 'https://nyc3.digitaloceanspaces.com', }

Shrine.storages = {

Shrine::Storage::S3.new(public: true, **s3_options)

cache: Shrine::Storage::S3.new(public: true, prefix: "cache", upload_options: {acl: "public-read"}, s3_options), store: Shrine::Storage::S3.new(public: true, prefix: "store", upload_options: {acl: "public-read"}, s3_options), }

Check https://shrinerb.com/docs/plugins/activerecord for full list of plugins around ActiveRecord

Check https://shrinerb.com/docs/external/extensions for full list of plugins/extensions

Shrine.plugin :activerecord Shrine.plugin :cached_attachment_data # for retaining the cached file across form redisplays Shrine.plugin :restore_cached_data # re-extract metadata when attaching a cached file

Shrine.plugin :validation

Shrine.plugin :validation_helpers

Shrine.plugin :instrumentation # adds instrumentation

Shrine.plugin :direct_upload

Shrine.plugin :uppy_s3_multipart # load the plugin Shrine.plugin :backgrounding # adds background processing



### Ruby Version

3.0.3

### Shrine Version

3.4.0

### Anything else?

_No response_
masudhossain commented 1 year ago

Closing this. issue seems to be with companion.