Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Dec 1, 2023 · 7 comments · Fixed by #683

Comments

@leoplct
Copy link

leoplct commented Dec 1, 2023

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
Copy link
Contributor

Is this a duplicate of #522?

@leoplct
Copy link
Author

leoplct commented Dec 1, 2023

Is this a duplicate of #522?

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

@northeastprince
Copy link
Contributor

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

@drale2k
Copy link

drale2k commented Dec 1, 2023

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
Copy link
Contributor

seanpdoyle commented Dec 1, 2023

@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
Copy link

augustosamame commented Jan 5, 2024

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
Copy link

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

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

michaelbaudino added a commit to michaelbaudino/turbo-rails that referenced this issue Apr 26, 2024
This provides compatibility with Sidekiq as an ActiveJob adapter (because [Sidekiq only allows native JSON types][1] to be passed as job arguments).

All credit goes to [@jdelStrother] who [suggested this solution][2].

Fixes [hotwired#522] and [hotwired#535]

[1]: https://github.com/sidekiq/sidekiq/wiki/Best-Practices#1-make-your-job-parameters-small-and-simple
[2]: hotwired#535 (comment)
[@jdelStrother]: https://github.com/jdelStrother
[hotwired#522]: hotwired#522
[hotwired#535]: hotwired#535
AnalyzePlatypus added a commit to AnalyzePlatypus/turbo-rails that referenced this issue Sep 19, 2024
dhh pushed a commit that referenced this issue Sep 19, 2024
@dhh dhh closed this as completed in #683 Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants