{"action":"created","issue":{"url":"https://api.github.com/repos/plataformatec/devise/issues/3550","labels_url":"https://api.github.com/repos/plataformatec/devise/issues/3550/labels{/name}","comments_url":"https://api.github.com/repos/plataformatec/devise/issues/3550/comments","events_url":"https://api.github.com/repos/plataformatec/devise/issues/3550/events","html_url":"https://github.com/plataformatec/devise/issues/3550","id":66183744,"number":3550,"title":"ActiveJob Integration on Rails 4.2 - Couldn't find User","user":{"login":"Jack12816","id":2496275,"avatar_url":"https://avatars.githubusercontent.com/u/2496275?v=3","gravatar_id":"","url":"https://api.github.com/users/Jack12816","html_url":"https://github.com/Jack12816","followers_url":"https://api.github.com/users/Jack12816/followers","following_url":"https://api.github.com/users/Jack12816/following{/other_user}","gists_url":"https://api.github.com/users/Jack12816/gists{/gist_id}","starred_url":"https://api.github.com/users/Jack12816/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jack12816/subscriptions","organizations_url":"https://api.github.com/users/Jack12816/orgs","repos_url":"https://api.github.com/users/Jack12816/repos","events_url":"https://api.github.com/users/Jack12816/events{/privacy}","received_events_url":"https://api.github.com/users/Jack12816/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-04-03T16:49:13Z","updated_at":"2015-11-26T13:55:00Z","closed_at":"2015-04-19T07:55:28Z","body":"Hello,\r\n\r\nas mentioned on the readme the ActiveJob integration on Rails 4.2 is as easy as adding\r\n```ruby\r\ndef send_devise_notification(notification, *args)\r\n  devise_mailer.send(notification, self, *args).deliver_later\r\nend\r\n```\r\nto the `User` model.\r\n\r\nThe good things is: a confirmation mail for a new user gets enqueued to my Sidekiq queue. But it looks like the job will be kicked off before the actual user instance is persisted. So the Sidekiq job fails for the first time. On a later retry the job gets done. **How can I ensure the user entity is persisted before we send any mails?**\r\n\r\nBacktrace:\r\n```bash\r\nsidekiq_1     | 2015-04-03T16:32:19.315Z 1 TID-oshefkll0 ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper JID-bb1b58a2b3543aca381d2068 INFO: start\r\nsidekiq_1     | 2015-04-03T16:32:19.348Z 1 TID-oshefkll0 ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper JID-bb1b58a2b3543aca381d2068 INFO: fail: 0.033 sec\r\nsidekiq_1     | 2015-04-03T16:32:19.349Z 1 TID-oshefkll0 WARN: {\"retry\"=>true, \"queue\"=>\"mailers\", \"class\"=>\"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper\", \"args\"=>[{\"job_class\"=>\"ActionMailer::DeliveryJob\", \"job_id\"=>\"6a519d5a-d2f6-4b4f-9490-4aa06a6c451c\", \"queue_name\"=>\"mailers\", \"arguments\"=>[\"UserMailer\", \"confirmation_instructions\", \"deliver_now\", {\"_aj_globalid\"=>\"gid://api/User/1\"}, \"4-c3GN3_g2iMMkgsKMnJ\", {}]}], \"jid\"=>\"bb1b58a2b3543aca381d2068\", \"enqueued_at\"=>1428078739.304505, \"error_message\"=>\"Error while trying to deserialize arguments: Couldn't find User with 'id'=1\", \"error_class\"=>\"ActiveJob::DeserializationError\", \"failed_at\"=>1428078739.34841, \"retry_count\"=>0}\r\nsidekiq_1     | 2015-04-03T16:32:19.349Z 1 TID-oshefkll0 WARN: Error while trying to deserialize arguments: Couldn't find User with 'id'=1\r\nsidekiq_1     | 2015-04-03T16:32:19.349Z 1 TID-oshefkll0 WARN: /home/web/.gem/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/core.rb:154:in `find'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/globalid-0.3.3/lib/global_id/locator.rb:126:in `locate'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/globalid-0.3.3/lib/global_id/locator.rb:17:in `locate'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/activejob-4.2.0/lib/active_job/arguments.rb:88:in `deserialize_global_id'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/activejob-4.2.0/lib/active_job/arguments.rb:74:in `deserialize_argument'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/activejob-4.2.0/lib/active_job/arguments.rb:38:in `block in deserialize'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/activejob-4.2.0/lib/active_job/arguments.rb:38:in `map'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/activejob-4.2.0/lib/active_job/arguments.rb:38:in `deserialize'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/activejob-4.2.0/lib/active_job/core.rb:85:in `deserialize_arguments'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/activejob-4.2.0/lib/active_job/core.rb:75:in `deserialize_arguments_if_needed'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/activejob-4.2.0/lib/active_job/execution.rb:30:in `perform_now'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/activejob-4.2.0/lib/active_job/execution.rb:21:in `execute'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/activejob-4.2.0/lib/active_job/queue_adapters/sidekiq_adapter.rb:40:in `perform'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/processor.rb:75:in `execute_job'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/processor.rb:52:in `block (2 levels) in process'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/middleware/chain.rb:127:in `call'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/middleware/chain.rb:127:in `block in invoke'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/middleware/server/active_record.rb:6:in `call'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/middleware/server/retry_jobs.rb:74:in `call'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/middleware/server/logging.rb:11:in `block in call'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/logging.rb:24:in `with_context'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/middleware/server/logging.rb:7:in `call'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/middleware/chain.rb:132:in `call'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/middleware/chain.rb:132:in `invoke'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/processor.rb:51:in `block in process'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/processor.rb:98:in `stats'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/sidekiq-3.3.2/lib/sidekiq/processor.rb:50:in `process'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `public_send'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `dispatch'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:122:in `dispatch'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/cell.rb:60:in `block in invoke'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/cell.rb:71:in `block in task'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/actor.rb:357:in `block in task'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/tasks.rb:57:in `block in initialize'\r\nsidekiq_1     | /home/web/.gem/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:15:in `block in create'\r\n```\r\n\r\nVersions:\r\n* rails: 4.2.0\r\n* devise: 3.4.1\r\n* warden: 1.2.3"},"comment":{"url":"https://api.github.com/repos/plataformatec/devise/issues/comments/159921593","html_url":"https://github.com/plataformatec/devise/issues/3550#issuecomment-159921593","issue_url":"https://api.github.com/repos/plataformatec/devise/issues/3550","id":159921593,"user":{"login":"dennym","id":1562328,"avatar_url":"https://avatars.githubusercontent.com/u/1562328?v=3","gravatar_id":"","url":"https://api.github.com/users/dennym","html_url":"https://github.com/dennym","followers_url":"https://api.github.com/users/dennym/followers","following_url":"https://api.github.com/users/dennym/following{/other_user}","gists_url":"https://api.github.com/users/dennym/gists{/gist_id}","starred_url":"https://api.github.com/users/dennym/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dennym/subscriptions","organizations_url":"https://api.github.com/users/dennym/orgs","repos_url":"https://api.github.com/users/dennym/repos","events_url":"https://api.github.com/users/dennym/events{/privacy}","received_events_url":"https://api.github.com/users/dennym/received_events","type":"User","site_admin":false},"created_at":"2015-11-26T13:55:00Z","updated_at":"2015-11-26T13:55:00Z","body":"go for my solution one post above yours. We used it for a while and the error disappeared. we just had to drop it again because it was interfering with our custom email params."}}