Skip to content

Private tables should always be saved in private db.#310

Merged
mbrandonw merged 2 commits into
mainfrom
fix-private-table-zone
Nov 27, 2025
Merged

Private tables should always be saved in private db.#310
mbrandonw merged 2 commits into
mainfrom
fix-private-table-zone

Conversation

@mbrandonw
Copy link
Copy Markdown
Member

We currently have a bug with private tables + sharing where we accidentally try to save rows from the private table in the shared db, and that causes a permission failure. This PR makes sure that private tables are always saved in the private DB.

Comment on lines +365 to +373
let zoneNameOverride: SQLQueryExpression<String?>
let ownerNameOverride: SQLQueryExpression<String?>
if privateTables.contains(where: { $0.base.tableName == Base.tableName }) {
zoneNameOverride = #sql("\(quote: defaultZone.zoneID.zoneName, delimiter: .text)")
ownerNameOverride = #sql("\(quote: defaultZone.zoneID.ownerName, delimiter: .text)")
} else {
zoneNameOverride = #sql("NULL")
ownerNameOverride = #sql("NULL")
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main fix. If we are getting parent information for a private table we can make sure the zone is the default zone. We could probably clean this up a bit, I mostly just focused on getting a passing test.

}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func privateTablesStayInPrivateDatabase() async throws {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test failed before the fix because when processing record changes in the private database a failure would be emitted since there were no changes to process.

databaseScope: .private,
storage: [
[0]: CKRecord(
recordID: CKRecord.ID(1:remindersListPrivates/zone/__defaultOwner__),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that this record is in the private database shows the fix has worked.

@mbrandonw mbrandonw merged commit d471d29 into main Nov 27, 2025
5 checks passed
@mbrandonw mbrandonw deleted the fix-private-table-zone branch November 27, 2025 01:47
bok- pushed a commit to bok-/sqlite-data-with-traits that referenced this pull request Dec 15, 2025
* Private tables should always be saved in private db.

* snapshots
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