Skip to content

Keep model values intact when an update fails - #395

Merged
taylorotwell merged 1 commit into
laravel:0.xfrom
shuvroroy:fix/retry-failed-model-update
Dec 1, 2026
Merged

taylorotwell merged 1 commit into
laravel:0.xfrom
shuvroroy:fix/retry-failed-model-update

Conversation

@shuvroroy

@shuvroroy shuvroroy commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

A uniqueness violation could leave a model holding the values the database rejected. After the conflict was removed, retrying the same update returned Ok(()) because the instance already appeared to have those values. Reloading the row still returned the original data.

Instance updates now apply assignments and the updating hook to a working copy. Once the write succeeds, the caller receives the new values before Updated listeners run. This lets callers retry a rejected write on the same instance and keeps the model in sync when a listener reports an error after a successful write.

Verification

  • Reproduced the bug on 0.x with a SQLite uniqueness constraint. The regression checks the name, email and timestamp after failure and reloads the row after retry.
  • Covered errors from the updating hook and from an Updated listener.
  • 360 SQLite database tests and all 7 model-user tests passed.
  • cargo fmt --all -- --check passed.

@taylorotwell
taylorotwell merged commit a1b542b into laravel:0.x Dec 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants