Change Enterprise after_create callback to after_create_commit

As a general rule, if you're triggering an email job as part of an after create/save callback, it should use after commit instead.

Why? The transaction can't finish until after the record is persisted (the data is committed) which includes the logic in all callbacks. So for example if the transaction fails after the email job has been placed it will be rolled back, but the email job will already be in the queue, and it'll be referencing a record that doesn't actually exist (due to the rollback).
This commit is contained in:
Matt-Yorkley
2021-05-02 12:56:06 +01:00
parent 8672969798
commit 2560757ea2

View File

@@ -105,7 +105,7 @@ class Enterprise < ApplicationRecord
after_touch :touch_distributors
after_create :set_default_contact
after_create :relate_to_owners_enterprises
after_create :send_welcome_email
after_create_commit :send_welcome_email
after_rollback :restore_permalink