Repository navigation
Fix save() leaving the model dirty after a quiet save - #391
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Checklist
Description
$model->withoutHook()->save()wrote the row but left the model dirty.save()only syncedoriginalAttributesinside the "hooks not suppressed" branch, so after a quiet save the model still treated the change as unsaved.update()already syncs unconditionally, so the two methods disagreed.Impact
After a quiet save on the same instance:
getDirtyAttributes()andisDirtyAttr()still reported the persisted change, andgetOriginal()returned the stale value.save()with no new edits ran a secondUPDATEand firedafter_updatedand the property watchers for a change that was already stored. The quiet save was meant to avoid exactly that, and the hook fired late and unexpectedly.Changes
save()now syncsoriginalAttributesafter every successful update. Onlyafter_updatedand the property watchers stay conditional on hooks not being suppressed.getOriginal()keeps returning the old value insideafter_updated.EntityModelHookTestand 1 inWatcherTest. They cover model state after a quiet save, the later plainsave()(no re-fired hook, no rewritten row), suppression lasting one write only, other instances of the same row, hook ordering, parity withupdate(), and a property watch not firing late.Backward Compatibility
Hook and watcher behavior is unchanged. The only difference is that a model is no longer reported dirty for a change that has already been written. Code that relied on the stale dirty state to re-save the same change would stop doing so, which is the intended fix.
Checklist