-
-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
ActiveSupport::CurrentAttributes Compatibility #1341
Comments
This is a bug in rails: rails/rails#49227, there's also a bit more info at #1320 and its linked issues/prs/blogpost. I agree it's very unexpected. |
That's the correct issue @Earlopain that explains the problem. Thank you! In this example, it's somewhat worse because good_job/app/models/good_job/batch.rb Lines 104 to 105 in fbd1a5b
Is this example code you're running in a test or console and is there an active Rails executor? ( Rails now wraps all test cases with an executor (though I think you must opt in). RSpec has not done so yet, though there are workarounds: rspec/rspec-rails#2713 Background:
|
Ah, right. Yeah, I wasn't thinking about potential executor things going on under the hood for batches. Rails made the executor around test cases the default for 7.0. So, if you do |
Okay that makes sense. Yes, I was running it directly in the console to test the job. Perhaps console sessions should also be wrapped with Consider the example: $ rails console
Loading development environment (Rails 7.0.8.1)
# Fail
Current.user = User.find(id)
MyGoodJob.new.perform(...)
# Success
Rails.application.executor.wrap do
Current.user = User.find(id)
MyGoodJob.new.perform(...)
end |
Closing this as I'm finding many other discussions about this elsewhere |
I have an interesting bug report for you.
Let's say you use
ActiveSupport::CurrentAttributes
:And you want to use it with GoodJob:
I looked into this and the reason is the good job calls the function
Rails.application.executor.wrap
twice in this code which does work to ensure isolated execution state. Part of that work includes callingreset
on all descendants ofActiveSupport::CurrentAttributes
. This resets all of the attributes.I'm not sure if this is an issue or expected behavior. I think it should at least be documented. This is the workaround I've come up with so far
Thanks for your again for your work on this project! @bensheldon
The text was updated successfully, but these errors were encountered: