Fix `MockCloudDatabase` record mutation in modify callback by lukaskubanek · Pull Request #412 · pointfreeco/sqlite-data · GitHub
Skip to content

Fix MockCloudDatabase record mutation in modify callback - #412

Closed
lukaskubanek wants to merge 2 commits into
pointfreeco:mainfrom
structuredpath:copy-records-in-mock-notify
Closed

lukaskubanek wants to merge 2 commits into
pointfreeco:mainfrom
structuredpath:copy-records-in-mock-notify

Conversation

@lukaskubanek

Copy link
Copy Markdown
Contributor

When calling MockCloudDatabase.modifyRecords(…), the returned callback currently passes the saved records to the sync engine as-is (i.e. the internally copied and stored CKRecord instances). This effectively shares the same CKRecord objects with the sync engine.

Mutations performed on these records by the sync engine (such as updating userModificationTime as part of the upsert logic1) are therefore reflected in the MockCloudDatabase. As a result, the mock database can report incorrect results, as demonstrated by the newly introduced assertion in one of the merge conflict tests.

This PR fixes the issue by returning copies of the records in the modify callback, preventing the coupling between the sync engine and MockCloudDatabase.

Footnotes

  1. One could question whether directly mutating the CKRecord in the upsert logic is appropriate, and whether a better approach exists (see #370). However, that’s a separate topic. ↩

@lukaskubanek

Copy link
Copy Markdown
Contributor Author

lukaskubanek added a commit to structuredpath/sqlite-data that referenced this pull request Mar 26, 2026
lukaskubanek added a commit to structuredpath/sqlite-data that referenced this pull request Mar 26, 2026
@mbrandonw

Copy link
Copy Markdown
Member

Should I amend this PR or submit it separately after the initial conflict resolution PRs have been reviewed?

Hi @lukaskubanek, considering that #507 now subsumes this PR, how about a new PR for the behavior you describe above?

@lukaskubanek

lukaskubanek commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor Author

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