{"id":"228bdaccce42b1a7","repo":"laravel/framework","slug":"queueable-entity-s-not-found-for-id-s","errorCode":null,"errorMessage":"Queueable entity [%s] not found for ID [%s].","messagePattern":"Queueable entity \\[(.+?)\\] not found for ID \\[(.+?)\\]\\.","errorType":"exception","errorClass":"EntityNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Eloquent/QueueEntityResolver.php","lineNumber":27,"sourceCode":"{\n    /**\n     * Resolve the entity for the given ID.\n     *\n     * @param  string  $type\n     * @param  mixed  $id\n     * @return mixed\n     *\n     * @throws \\Illuminate\\Contracts\\Queue\\EntityNotFoundException\n     */\n    public function resolve($type, $id)\n    {\n        $instance = (new $type)->find($id);\n\n        if ($instance) {\n            return $instance;\n        }\n\n        throw new EntityNotFoundException($type, $id);\n    }\n}\n","sourceCodeStart":9,"sourceCodeEnd":30,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Eloquent/QueueEntityResolver.php#L9-L30","documentation":"QueueEntityResolver::resolve() loads (new $type)->find($id) when the queue worker needs the model that was serialized by reference. If the row no longer exists (deleted between dispatch and processing), find() returns null and EntityNotFoundException is thrown with the type and id. This surfaces as the job failing because its payload model disappeared.","triggerScenarios":"Dispatching a queued job/closure/mailable that serializes a model by id (SerializesModels), then the model is deleted (force-deleted, or soft-deleted and the job expects it) before the worker picks it up.","commonSituations":"Race between an edit/delete and a queued notification; soft-deleted models fetched without withTrashed in the job; jobs that outlive their referenced data; tests that dispatch then truncate tables.","solutions":["In the job's handle(), catch ModelNotFoundException/EntityNotFoundException and fail gracefully or skip.","Serialize full model data instead of a reference when the job does not need a live row, or pass the id and re-fetch with withTrashed()/fail() defensively.","Avoid deleting referenced entities while jobs are pending, or mark them as in-use until jobs complete."],"exampleFix":"// before\nclass SendReport implements ShouldQueue {\n    public function __construct(public User $user) {}\n    public function handle() { $this->user->notify(...); } // throws if deleted\n}\n\n// after\nclass SendReport implements ShouldQueue {\n    public function __construct(public User $user) {}\n    public function handle() {\n        $user = User::withTrashed()->find($this->user->id)\n            ?? throw new ModelNotFoundException;\n        $user->notify(...);\n    }\n}","handlingStrategy":"try-catch","validationCode":"// Verify the referenced entity still exists before the job runs (best-effort)\nif (! (new $type)->whereKey($id)->exists()) {\n    throw new \\Illuminate\\Contracts\\Queue\\EntityNotFoundException($type, $id);\n}","typeGuard":null,"tryCatchPattern":"try {\n    $model->notify(...);\n} catch (\\Illuminate\\Contracts\\Queue\\EntityNotFoundException $e) {\n    // log and release/fail gracefully\n    report($e);\n    return;\n}","preventionTips":["Fetch models inside handle() with withTrashed()/fail() defensively.","Avoid deleting entities referenced by queued jobs until they complete.","Prefer passing ids over model references when data may change."],"tags":["eloquent","queue","serialization","race-condition","entity-resolution"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}