Skip to content

HandleModelNotFound() method uses displayName() method of the job as class name #54502

@JochemLettink

Description

@JochemLettink

Laravel Version

11.41.3

PHP Version

8.4.3

Database Driver & Version

Mysql 8.0.40 - Debian 12

Description

When pushing a job to the database queue using the displayName() method to set a custom display name in the queue worker, and with the $deleteWhenMissingModels property set to true, a ModelNotFoundException is still logged and the job is going through the fail() lifecycle if the model is deleted in the meantime.

This happens because the handleModelNotFound() method in CallQueueHandler resolves the job name using $class = $job->resolveName();, which calls JobName::resolve($this->getName(), $this->payload()); This method returns the displayName, which is not a valid class name because the displayName is changed.

As a result, ReflectionClass fails to reflect the class, causing the system to incorrectly determine that shouldDelete is false, leading to running the fail() lifecycle of the job in stead of quietly discard the job.

Steps To Reproduce

  1. Create a database job with the $deleteWhenMissingModels property set to true
  2. Add a model to the constructor of the job
  3. Add an custom displayName() method to the job that returns an non existing class
  4. Create a test that creates the model, dispatches the job and delete the model before running the (DB) queue worker.
  5. Make sure to run the test expecting no errors to be logged.

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions