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
I think that the json_safe?
method should return true for symbols, to avoid the "Job arguments to **** must be native JSON types" error
#5252
Comments
json_safe?
method should return true for symbols, to avoid the "Job arguments to ShrineJob must be native JSON types" errorjson_safe?
method should return true for symbols, to avoid the "Job arguments to **** must be native JSON types" error
I've just noticed another place where this is happening in my code:
I'm actually using symbols as hash keys all over my app for this What do you think about this change?
|
Sorry for the noise, I read through the discussion in #5071. I can see that symbols are intentionally banned for this reason (with strict args):
I suppose I will need to use EDIT: Just another 2 cents... I was thinking some more, and symbols are such a big part of Ruby that it would be even nicer if you could use some different marshaling format that actually preserved the difference between symbols and strings. It feels really weird to use strings as args or hash keys when the rest of my app uses symbols everywhere else. It feels like the bug here is using JSON, which doesn't fully support Ruby data types (since Sidekiq is Ruby on Rails job processor, and symbols are a big part of Ruby code.) Maybe a future Sidekiq version could use msgpack with an extension type for symbols. This would also be great for dates and times. Anyway, that's enough from me. Hope you're having a good week! |
“with_indifferent_access” is an ActiveSupport thing. Sidekiq doesn’t depend
on ActiveSupport. You can write your own middleware, see
#5246
…On Tue 22. Mar 2022 at 01:40, Nathan Broadbent ***@***.***> wrote:
Closed #5252 <#5252>.
—
Reply to this email directly, view it on GitHub
<#5252 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AASQMEXNDG2BP35Y4XPUIULVBEJG7ANCNFSM5RJHVOMA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Ruby version: 2.7.1
Rails version: 6.0.4.6
Sidekiq / Pro / Enterprise version(s): Sidekiq 6.4.0
I had to hunt down why the
Job arguments to #{item["class"]} must be native JSON types
error was happening inlib/sidekiq/job_util.rb
. It turned out thatjson_safe?(item)
was returning false because I passing in a symbol as the first job argument. I have some Shrine uploader jobs that use symbols for the action arg (:promote
,:delete
):I believe it's generally safe to convert symbols to strings, so I was wondering if
json_safe?
could be a bit more lenient. Here's the original method:What do you think about this change?
(Could even go a little further to ignore symbols in hash keys:
arg.is_a?(Hash) ? arg.with_indifferent_access : arg
)I don't feel too strongly about it, but it would have just saved me a little bit of time. Would you accept a PR with this change? (No worries if not, I'm happy to switch them to strings.)
The text was updated successfully, but these errors were encountered: