Sometimes I get (Ecto.StaleEntryError) attempted to update a stale struct
when trying to update record.
I haven't found any recipe to avoid this in Ecto's docs, so what should I do to avoid this?
P.S. I'm using PostgreSQL 9.6 via Postgrex, Ecto 2.1.3.
Looks like you are fetching a schema from the database and updating it after it has been updated somewhere else in your app. Are you fetching, hanging onto it, and updating later? If so, fetch, change, and update.
Right from the Ecto docs:
When a conflict happens (a record which has been previously fetched is
being updated, but that same record has been modified since it was
fetched), an `Ecto.StaleEntryError` exception is raised.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With