Confirmation Mail sometimes failing on Resque #2035

Closed
cfcosta opened this Issue Aug 21, 2012 · 1 comment

Projects

None yet

2 participants

@cfcosta
cfcosta commented Aug 21, 2012

A few days ago, I've had a few failing jobs on Resque to send confirmation e-mails with ActiveRecord::RecordNotFound errors, because Resque tried to send the e-mail after the resource is created, but before database commit.

Changing this on Confirmable did the trick, but some tests failed because devise's test suit uses ActiveSuport::TestCase.use_transactional_fixtures, and the mail is never sent, since the transaction is never commited.

diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb
index f21ecb7..a50c9ee 100644
--- a/lib/devise/models/confirmable.rb
+++ b/lib/devise/models/confirmable.rb
@@ -34,7 +34,7 @@ module Devise

       included do
         before_create :generate_confirmation_token, :if => :confirmation_required?
-        after_create  :send_on_create_confirmation_instructions, :if => :confirmation_required?
+        after_commit  :send_on_create_confirmation_instructions, :if => :confirmation_required?
         before_update :postpone_email_change_until_confirmation, :if => :postpone_email_change?
         after_update  :send_confirmation_instructions, :if => :reconfirmation_required?
       end

Any ideas?

@josevalim
Member

Yeah, check this:

mhfs/devise-async#6

We won't default to after_commit, but there is a mechanism on master that allows you to fix this issue.

@josevalim josevalim closed this Aug 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment