Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

after_email callback ran even though the if check returns false #307

Closed
weizheheng opened this issue Sep 5, 2023 · 0 comments
Closed

after_email callback ran even though the if check returns false #307

weizheheng opened this issue Sep 5, 2023 · 0 comments

Comments

@weizheheng
Copy link

weizheheng commented Sep 5, 2023

Hi, I would like to ask is it by design that the after_email callback still get runs even though no email has been sent?

My current use case:

class ReturnOrders::AfterSubmitNotification < Noticed::Base
  deliver_by :email, mailer: "ReturnOrderMailer", method: :submitted_for_customer, if: :notification_enabled?

  after_email :record_notification_activity

  private

  def record_notification_activity
    NotificationActivity.create()
  end

  def notification_enabled?
    notification.enabled?
  end
end

Expectation

  1. If the notification is disabled, no email should be sent.
  2. It should not hit the after_email callback so no NotificationActivity is created.

Actual

  1. If the notification is disabled, no email is sent.
  2. However, it still hit the after_email which creates the NotificationActivity even though no email has been sent.

Question

  1. Is the after_email callback going to get called no matter the email is sent or not?
  2. Any suggestions to handle my use case above? Should I just do the same if check for the after_email callback?
after_email :record_notification_activity, if: :notification_enabled?
Repository owner locked and limited conversation to collaborators Oct 31, 2023
@Kentasmic Kentasmic converted this issue into discussion #320 Oct 31, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant