Skip to content

Don't replace lastKnownServerRecord with an older fetched record - #589

Open
sainadth wants to merge 1 commit into
pointfreeco:mainfrom
sainadth:keep-newer-last-known-server-record
Open

sainadth wants to merge 1 commit into
pointfreeco:mainfrom
sainadth:keep-newer-last-known-server-record

Conversation

@sainadth

Copy link
Copy Markdown

Fixes #585.

upsertFromServerRecord stored every fetched record as lastKnownServerRecord, even when it was older than the stored one. A fetch that started before a save finished could deliver the pre-save record, and the next save of it then failed with .serverRecordChanged.

This applies the same check as refreshLastKnownServerRecord: the stored record is replaced only when the fetched record's modification date is at least as new. That applies to both places upsertFromServerRecord writes it.

The new test fetchedOlderRecordDoesNotReplaceLastKnownServerRecord saves a list twice, then delivers the first copy as a fetched change. It fails without the fix.

One thing left as is: the fetched record's row data is still merged into the table. Plain fields keep their newer values through the per-field timestamps (the test checks this), but an asset column could still revert if the stored record's asset file is missing (the path in #584). Returning before the row update would avoid that but changes more, so I left it out. Happy to add it if you'd like.

Tested with swift test --traits SQLiteDataTagged in debug and release, and the Reminders and SyncUps example tests, on Xcode 27.1.

🤖 Generated with Claude Code

upsertFromServerRecord stored every fetched record as
lastKnownServerRecord, even when it was older than the stored one. A
fetch that started before a save finished could deliver the pre-save
record, and the next save of it then failed with .serverRecordChanged.

Apply the same check as refreshLastKnownServerRecord: replace the stored
record only when the fetched record's modification date is at least as
new.

Fixes pointfreeco#585.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

A fetch that completes after a save sets lastKnownServerRecord back to the older record, so the next save conflicts

1 participant