BlobKey, MirrorService and Sidekiq 8 are incompatible

未關閉
#573 3 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

@const-cloudinary 已經在處理了。

開始於 2025年5月22日。

評估

這個 Issue 還沒有評估資料。

描述

Bug report for Cloudinary Ruby SDK

Describe the bug in a sentence or two.

When using the Cloudinary ActiveStorage service in a mirror with S3 and Sidekiq 8 as a job queue, I am getting errors of the form

Job arguments to ActiveStorage::MirrorJob must be native JSON types, but "1xfiunhqeexf8h3pkdxucnby5eou" is a ActiveStorage::BlobKey

Issue Type (Can be multiple)

  • Build - Cannot install or import the SDK
  • Performance - Performance issues
  • Behaviour - Functions are not working as expected (such as generate URL)
  • Documentation - Inconsistency between the docs and behaviour
  • Other (Specify)

Steps to reproduce

  • Use Sidekiq 8 with strict_args enabled (default)
  • Define an S3 service and a Cloudinary Service in storage.yml
  • Define a mirror as
mirror:
  service: Mirror
  primary: amazon
  mirrors:
    - cloudinary
  • Attempt to upload a file
  • ActiveStorage will attempt to enqueue ActiveStorage::MirrorJob which takes key as an arg. But because the Cloudinary gem is redefining the key as a BlobKey we get the above error from Sidekiq because BlobKey is not a native JSON type.

Error screenshots or Stack Trace (if applicable)

lib/active_storage/service/mirror_service.rb:55

A minimal repro can be achieved with the following:

> s = ActiveStorage::Service::MirrorService.new(primary: nil, mirrors: [])
=> #<ActiveStorage::Service::MirrorService:0x0000ffff69a5d2f0 @mirrors=[], @primary=nil>
> k = ActiveStorage::BlobKey.new(key: "test")
=> "test"
> s.mirror_later(k, checksum: nil)
INFO  2025-05-15T14:47:39.511Z pid=955 tid=25v: Sidekiq 8.0.3 connecting to Redis with options {size: 10, pool_name: "internal", url: "redis://redis:6379/0"}
Failed enqueuing ActiveStorage::MirrorJob to Sidekiq(default): ArgumentError (Job arguments to ActiveStorage::MirrorJob must be native JSON types, but "test" is a ActiveStorage::BlobKey.
See https://github.com/sidekiq/sidekiq/wiki/Best-Practices
To disable this error, add `Sidekiq.strict_args!(false)` to your initializer.

This monkey patch to ActiveStorage can address the issue, but I dont know whether rails would want this in their core code when the expect the key to be a string anyway

module ActiveStorage
  class Service::MirrorService < Service
    def mirror_later(key, checksum:) # :nodoc:
      ActiveStorage::MirrorJob.perform_later key.to_s, checksum: checksum
    end
  end
end

Operating System

  • Linux
  • Windows
  • macOS
  • All

Environment and Libraries (fill in the version numbers)

  • Cloudinary Ruby SDK version - 2.3.0
  • Ruby Version - 3.4.3
  • Rails Version - 7.2.2.1
  • Other Libraries - ActiveStorage 7.2.2.1
主要語言
Ruby
星號
420
分支
282
PR 合併指標
30 天內沒有已合併 PR

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

cloudinary/cloudinary_gem 的其他 Issue

查看 cloudinary/cloudinary_gem 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。