Model saved event firing twice
I don't have any custom observers/events in this project. I have a model called File and when I upload a file in Filament the saved event on the model fires twice. When I manually create an entry in this model with tinker it only fires once. Anyone have any ideas? I've looked for stray
$model->update()
and $model->save()
and anything that could be listening.
I'm going to try and create a new fresh model to test as well, just curious if anyone has run into this? Searching I can't find anything so I suspect it's something dumb I've done somehow but not seeing it yet.5 Replies
I think I have a good clue. I switched to using the
created
event instead of updated
. The docs say updated gets called on either of those two cases. I used it because I wanted to catch either event for certain things I'm doing. But I'm going to break them out into their own now. Using created
solves my duplication issue for the moment. Still searching in case I forgot about adding a listener elsewhere but this is a small project and so far not seeing one.
I suspect something is immediately updating the record right after it's created.
Does Filament do anything like that when an upload is done specifically? I haven't noticed this on other events I've hooked into for filament. I chose to use the model event instead of the filament hook provided just because I like to keep all that in the model, fyi.
Confirmed that created_at and updated_at are 1 ms apart. Something is definitely updating it as soon as it's created.Are there any related models?
They do select a distributor to assign the file to.
Files do also have a child called Data (holds the individual rows)
Doesn’t sound like that’d be an issue. Just wondered if a relationship would cause it to update.
I'm still looking to make sure that's not happening. It has to be something in there. I'll find it. I've got a bigger issue that I need to solve first (using excel import lib and it works inline but not queued as a job - just fails silently which is super helpful lol). I'll circle back to this after I get that one solved.
I can't find it. There are only 4 updates in the whole app folder and a dozen a handful of saves. No after upload hooks in the resources, no listeners registered, no middleware. This one is hiding very well.
I got my bigger problem fixed and I'm going to let this one sit and come back to it with fresh eyes on Monday. I'm sure it's totally stupid. But in the meantime
created
works fine. I just want to know if it's my bug or a library.