#Dispatched Job Fails in Horizon Due to ModelNotFoundException

29 messages · Page 1 of 1 (latest)

somber badger
#

Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [Spatie\WebhookClient\Models\WebhookCall]. in /home/forge/example.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:621

#

We are facing this very frequently in the production server

We are using Valkey cache,laravel horizon

#

The data in the Db and not soft deleted as well

wicked basin
#

Show your job?

#

It’s certainly not in the db if you’re getting that error

somber badger
#

Yeah it marked as failed well but when we retry using the same payload then it works

#

when we query in db we found the data there

wicked basin
#

Then you must have a race condition somehow

#

Can’t really help without seeing the code

somber badger
#

The issue occurs when we pass the full Model instance as a parameter to the job it no longer works. However, if we pass only the model ID, it works correctly. This behaviour was working as expected previously. The problem started after upgrading the server from 2GB to 4GB RAM. We’ve identified the pattern, but the root cause is still unclear it seems unusual, but something in the upgrade likely triggered this change.

wicked basin
#

It’ll be unrelated to the ram upgrade, that’s a red herring

somber badger
#

I understand. There haven’t been any major code changes; it was working as expected before, but now it isn’t. What could be the potential cause, and is there a workaround?

wicked basin
#

I’m not fully familiar with the package but eloquent models are serialized into just their ids, put into the job payload, then re retrieved when running the job. That’s where this is originating from

#

There must’ve been a change somewhere, it wouldn’t just break

#

Unless you’re doing more in those jobs like findOrFail, do you have the full stack trace?

somber badger
#

This isn’t limited to a single job; most of the jobs are showing the same behaviour.

yeah i will share shortly

wicked basin
#

Could you show how you’re dispatching these?

#

It’s as if you’re dispatching before the model gets committed, like if you’re in a transaction

#

The model then saves, the job is retrying and marks itself as failed afterwards

somber badger
wicked basin
#

Alright now we’re going down a rabbit hole, when does that listener get fired

#

Well that shouldn’t matter, sorry I’m trying to help you debug while walking home

somber badger
#

Thank you ❤️ for your help with this. I tried for days on the server to identify the issue, but I couldn’t find the root cause or its source.

wicked basin
#

I’d recommend putting some basic logging around for whether the dispatch is sitting in an unclosed transaction (even across jobs), try retrieve the model straight after dispatch etc

somber badger
#

sure will do thank you