Fix pet record Blood/Allergies display and CloudKit tombstone conflict on delete/set-local - #52
Merged
Merged
Conversation
- Hide Blood and Allergies viewer sections for pet records (card viewer + list viewer)
The editor already hides them via `if record.isPet { EmptyView() }`; viewer now matches.
- Fix createTombstone to fetch existing CKRecord before saving, preventing
'record to insert already exists' error when deleting/setting-local a synced record.
This also fixes 'Set Local' not propagating deletion to other devices.
Co-authored-by: furfarch <121972251+furfarch@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix display and syncing issues for pet records
Fix pet record Blood/Allergies display and CloudKit tombstone conflict on delete/set-local
Feb 20, 2026
furfarch
approved these changes
Feb 21, 2026
There was a problem hiding this comment.
Pull request overview
This PR fixes two distinct issues in the Purus Health app: incorrect display of Blood and Allergies sections for pet records in the viewer, and a CloudKit tombstone creation failure that prevented deletion sync across devices.
Changes:
- Hide Blood and Allergies sections in the record viewer for pet records (both card and list views) to match the editor behavior
- Fix CloudKit tombstone creation by fetching existing records to obtain recordChangeTag before updating, resolving "record to insert already exists" errors
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| PurusHealth/Views/RecordEditorView.swift | Added if !record.isPet guards around Blood and Allergies sections in both cardPages and viewerFormList to hide these human-only sections for pet records |
| PurusHealth/Services/CloudSyncService.swift | Modified createTombstone to fetch existing CloudKit record first to obtain recordChangeTag, enabling UPDATE operations instead of failing INSERTs |
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.
Blood and Allergies sections were incorrectly shown in the viewer for pet records despite being suppressed in the editor. Both "Set Local" and cloud record deletion silently failed to write CloudKit tombstones due to a save conflict, preventing deletions from propagating to other devices.
Pet record viewer: hide Blood & Allergies
The editor already guards these sections with
if record.isPet { EmptyView() }. The viewer (both card TabView and list Form) had no equivalent guard. Addedif !record.isPetaround Blood and Allergies in bothcardPagesandviewerFormList.CloudKit tombstone: fix "record to insert already exists"
createTombstonewas constructing a freshCKRecord(recordType:, recordID:)without arecordChangeTag. CloudKit treats any save without a change tag as an INSERT — rejected when the record already exists in CloudKit.This silently broke both callers:
deleteSyncRecord→ error thrown and shown to the userdisableCloud(Set Local) → error caught and logged only; tombstone never written; other devices never saw the deletionFix: fetch the existing CKRecord first to obtain its change tag, then apply tombstone fields and save as an UPDATE. Fall back to INSERT only when the record is genuinely absent.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.