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
Error when providing a class argument to ActiveJob for classes that implement permitted?
#48561
Comments
permitted?
Removing these two lines allows rails/activejob/lib/active_job/arguments.rb Lines 93 to 94 in 06da26a
|
How about checking
- when -> (arg) { arg.respond_to?(:permitted?) }
+ when -> (arg) { arg.respond_to?(:permitted?) && arg.respond_to?(:to_h) } |
It'd be nice to explicitly check whether the class is The drawback with that approach though is Adding |
Resolves rails#48561 Co-authored-by: Sampat Badhe <sampatbadhe@gmail.com>
Steps to reproduce
permitted?
perform
method that accepts a class as a parameterBuggyJob.perform_later(MyClass)
The issue seems to be here: https://github.com/rails/rails/blob/main/activejob/lib/active_job/arguments.rb#L93
It seems in the switch statement to choose the correct serializer for the argument, we attempt to call
serialize_indifferent_hash
onargument.to_h
if it responds topermitted?
. I suppose the assumption here is that if the argument responds topermitted?
, it should be an instance ofActionController::Parameters
? In our app, we have a module that defines a class method namedpermitted?
for some other business logic and it's used in a few classes.Expected behavior
A BuggyJob job should successfully be queued, with the MyClass argument serialized using ActiveJob::Serializers::ModuleSerializer.
Actual behavior
A NoMethodError is raised:
System configuration
Rails version: Tested on 6.1.x, 7.0.x
Ruby version: Tested on 3.0.4
The text was updated successfully, but these errors were encountered: