Skip to content

Fix MockCloudDatabase record mutation in modify callback#412

Open
lukaskubanek wants to merge 2 commits intopointfreeco:mainfrom
structuredpath:copy-records-in-mock-notify
Open

Fix MockCloudDatabase record mutation in modify callback#412
lukaskubanek wants to merge 2 commits intopointfreeco:mainfrom
structuredpath:copy-records-in-mock-notify

Conversation

@lukaskubanek
Copy link
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.

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.

1 participant