Open Nowaker opened 8 years ago
I have no idea what the problem might be.
I've seen this in production in a few apps, my best guess is that Sidekiq is picking up the job before the transaction has completed. Adding a delay of a few seconds has fixed it in every case I've come across.
@KazW The real question is how. We can clearly see after_commit block is used. That means Sidekiq is either faster than light, or after_commit doesn't happen after the commit.
Ah, I've only used this with Devise 3.x when it was after_save... Nevermind!
No resolution on this then? We're experiencing this with other Sidekiq jobs. Does anybody know of a way to simulate this in a test environment (we're specifically using Postgres)? We have some linear code that basically goes
some_model = SomeModel.create!(...)
SomeAsyncService.new.perform(some_model)
The service kicks off a Sidekiq Job, which picks up the job (impressively) before the model is committed (despite a proper primary key being set etc).
@voltechs No resolution, unfortunately. Given Sidekiq cannot be faster than light, after_commit must happen technically after a commit but before the result of that commit is available to database clients.
I can clearly see after_commit being used in the code:
Yet, ActiveRecord::RecordNotFound still happens from time to time.
Any ideas how to fix it, @mperham?