Skip to content

SendNotificationsJob fails in console/cron context with Calling unknown method: craft\console\Request::getUserIP() #2535

@daanj1998

Description

@daanj1998

What happened?

Email notifications (admin, dynamic recipients, and email-field) are never delivered for any form that has "Store Submitted Data" disabled (storeData = false), when the Craft queue is run from the console (i.e. via a cron job, with Craft's runQueueAutomatically set to false).

No errors appear in the Freeform error log or in Craft's normal logs, because the failure happens inside the queued SendNotificationsJob. The job simply ends up in the failed queue.

Errors and Stack Trace (if available)

Error message stored on the failed queue job:


Calling unknown method: craft\console\Request::getUserIP()


Failing call:


Solspace\Freeform\Jobs\SendNotificationsJob::createTmpSubmission()
  -> Craft::$app->getRequest()->getUserIP()
     (request is craft\console\Request when the queue runs from cron)


(The full PHP stack trace is not persisted by the queue; the message above is the exact value stored in the `error` column of the failed `SendNotificationsJob` entries.)

How can we reproduce this?

  1. Configure Craft so the queue is not run automatically on web requests and is instead processed by a cron job:
    • runQueueAutomatically => false in config/general.php
    • Process the queue via the console, e.g. php craft queue/run (cron).
  2. Make sure Freeform sends notifications through the queue: Settings → General Settings → "Use the Queue for Email Notifications" = ON (useQueueForEmailNotifications = true).
  3. Create (or use) a form with Store Submitted Data = OFF (storeData = false) and at least one Admin (or email-field) notification configured with a valid recipient.
  4. Submit the form from the front end.
  5. Let the cron-driven queue process the job.

Expected: the notification email is sent to the configured recipient(s).

Actual: the SendNotificationsJob fails with Calling unknown method: craft\console\Request::getUserIP() and no email is ever sent. There is no entry in the Freeform error log.

Tip for confirming: with the same setup but runQueueAutomatically => true (queue runs inside a web request) the notification is sent correctly, because the request is then a craft\web\Request which has getUserIP(). Setting "Use the Queue for Email Notifications" = OFF also works around it, because the job then runs inline during the (web) submit request.

Freeform Edition

Pro

Freeform Version

5.14.21

Craft Version

5.10.3 (PHP 8.4.20)

When did this issue start?

  • Unsure
  • Fresh install of Freeform
  • After upgrading from older Freeform version
  • After upgrading from older Craft version
  • After a change to hosting configuration

Previous Freeform Version

No response

Metadata

Metadata

Labels

confirmedBug has been confirmedresolvedIssue has been resolved

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions