hotwired / turbo-rails

Use Turbo in your Ruby on Rails app
https://turbo.hotwired.dev
MIT License
2.11k stars 327 forks source link

Failed enqueuing Turbo::Streams::BroadcastStreamJob to Sidekiq(default): ArgumentError (Job arguments to Turbo::Streams::BroadcastStreamJob must be native JSON types, but "<turbo-stream action=\"refresh\"></turbo-stream>" is a ActiveSupport::SafeBuffer. #535

Closed leoplct closed 1 month ago

leoplct commented 10 months ago

I got this error when I updated the record.

Profile.find(1).update(column: true)

2023-12-01T10:36:33.323Z pid=8700 tid=pp0 INFO: Sidekiq 7.2.0 connecting to Redis with options {:size=>10, :pool_name=>"internal", :url=>nil, :network_timeout=>5}
Failed enqueuing Turbo::Streams::BroadcastStreamJob to Sidekiq(default): ArgumentError (Job arguments to Turbo::Streams::BroadcastStreamJob must be native JSON types, but "<turbo-stream action=\"refresh\"></turbo-stream>" is a ActiveSupport::SafeBuffer.
See https://github.com/sidekiq/sidekiq/wiki/Best-Practices
To disable this error, add `Sidekiq.strict_args!(false)` to your initializer.

Gemfile

rails (7.1.2)
sidekiq (7.2.0)
turbo-rails (>= 2.0.0.pre.beta.1)!

Active record


class Profile < ApplicationRecord
  broadcasts_refreshes

  # ...
en
seanpdoyle commented 10 months ago

Is this a duplicate of https://github.com/hotwired/turbo-rails/issues/522?

leoplct commented 10 months ago

Is this a duplicate of #522?

Maybe it's related, but It's a different error message.

northeastprince commented 10 months ago

It's the same underlying problem - SafeBuffers not being serialized.

drale2k commented 10 months ago

I am getting the same error. Running rails edge as recommended in #522 did not fix the issue for me. It does not seem to be the exact same issue but separate.

Gemfile:

rails (7.1.2) and tried on rails edge
sidekiq (7.2.0)
seanpdoyle commented 10 months ago

@drale2k thank you for double-checking. This is likely the same type of error as the Active Job variation, but specifically to Sidekiq's Active Job adapter.

augustosamame commented 9 months ago

I am getting the same error when updating a Rails model with the broadcasts_refreshes directive in it. I was testing the new features in Turbo 8 beta and subscribed views will not refresh. I assume it's because of this issue.

rails 7.1.2 sidekiq 7.2.0 turbo-rails 2.0.0.pre.beta

any ideas?

Edit: Adding Sidekiq.strict_args!(false) to my sidekiq initializer as recommended in #522 fixed the issue. I wonder if there could be any side effects from this though. That being said, Turbo 8 is rocking it! Great job!

jdelStrother commented 8 months ago

Adding Sidekiq.strict_args!(false) to my sidekiq initializer as recommended in https://github.com/hotwired/turbo-rails/issues/522 fixed the issue. I wonder if there could be any side effects from this though

Rather than just disabling sidekiq's args-checking, another alternative might be to add this monkeypatch in an initializer:

Rails.application.config.after_initialize do
  Turbo::Streams::BroadcastStreamJob.class_eval do
    def self.perform_later(stream, content:)
      super(stream, content: content.to_str)
    end
  end
end