Skip to content

RecordNotFound error when using ActionMailer's deliver_later method #36

Description

@cobalamin

I'm using ActionMailer to deliver mails on model creation. My controller code looks like this:

if @flaw.save
  render :show, status: :created

  FlawMailer.user_email(@flaw).deliver_later
  FlawMailer.reported_email(@flaw).deliver_later
else
...

I'm using deliver_later as I don't want the HTTP response by mailing concerns. However, this doesn't work and throws an error, apparently it's trying to use the obfuscated id to look up the Flaw model (even though I'm passing it as a parameter:

[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 61049335-05ca-452e-8161-205b7c4bde72) to Inline(mailers) with arguments: "FlawMailer", "user_email", "deliver_now", gid://app/Flaw/18
[ActiveJob]   Flaw Load (0.3ms)  SELECT  "flaws".* FROM "flaws" WHERE "flaws"."id" = ?  ORDER BY created_at DESC LIMIT 1  [["id", 1928367482]]
Completed 500 Internal Server Error in 1596ms (Views: 26.2ms | ActiveRecord: 3.8ms)

ActiveRecord::RecordNotFound (Couldn't find Flaw with 'id'=1928367482):
  app/controllers/flaws_controller.rb:19:in `create'

When I use deliver_now instead, this problem vanishes. So there seems to be some incompatibilities between this gem and ActionMailer's deliver_later method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions