After making a non-breaking change to my schema, I am getting this error:
ending session with error: non-breaking schema change: adding “Bool” column at field “`\xa4\xac\xfd\x9d\xe5\x00\x00;\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00” in schema “CarePlan”, schema changes from clients are restricted when developer mode is disabled (ProtocolErrorCode=225)
Here is my schema before:
class CarePlan: Object, ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var _id: ObjectId
@Persisted var assessmentId: ObjectId?
@Persisted var createdAt: Date = Date()
@Persisted var createdById: ObjectId?
@Persisted var recipientId: ObjectId?
@Persisted var requireResponsesToAllCarePlanTasks: Bool?
@Persisted var sections: List<CarePlan_sections>
@Persisted var serviceId: ObjectId?
@Persisted var signedAt: Date?
@Persisted var tasks: List<CarePlan_tasks>
@Persisted var updatedAt: Date = Date()
@Persisted var workspaceId: ObjectId
}
And here is the updated schema:
class CarePlan: Object, ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var _id: ObjectId
@Persisted var assessmentId: ObjectId?
@Persisted var createdAt: Date = Date()
@Persisted var createdById: ObjectId?
@Persisted var recipientId: ObjectId?
@Persisted var requireResponsesToAllCarePlanTasks: Bool?
@Persisted var requireCareSummary: Bool?
@Persisted var sections: List<CarePlan_sections>
@Persisted var serviceId: ObjectId?
@Persisted var signedAt: Date?
@Persisted var tasks: List<CarePlan_tasks>
@Persisted var updatedAt: Date = Date()
@Persisted var workspaceId: ObjectId
}
The only difference is the optional Bool requireCareSummary.
Notes about my device sync implementation:
Development mode is disabled
I maintain two apps: one for iOS and one for Android
I have only seen this error for the iOS app in the Device Sync logs located on the Atlas dashboard
For the Swift iOS app, I am using a Realm instance configured with a flexibleSyncConfiguration.
Questions:
Why is this error occurring?
How do I prevent it when I make another non-breaking schema change?
If I can’t prevent it, what logic should I include in my Realm Sync Manager Error Handler to resolve it gracefully?
Can I configure my app to clear the local realm on an app store update?
That usually means an updated version of the app (i.e. one that already had a new field - odd that the name is being mangled, though) was talking to a backend that doesn’t know about that field: as it can’t change the schema (Dev Mode is disabled - and rightly so, if it’s Production), it generates the error. If the app was updated before the schema change was applied, it’s a normal thing to happen.
Again, the unusual thing here is the name of the field mangled in a strange way: it could be that the iOS source code is using an odd encoding, have you looked into the local Realm file to check that the names of the fields match?
Yes, but why would you do that? If a schema change is breaking, or the client file is too outdated, the SDK will perform a Client Reset anyway, be sure to handle that properly instead.
After using Realm Studio to view the local realm file that is generated when I run my app using the Xcode Simulator, I can confirm the requireCareSummary field is displayed as expected. I’ll try seeing if I can match the device and iOS version of one of the users experiencing this error and see if that changes anything about the realm file field name.
If a schema change is breaking, or the client file is too outdated, the SDK will perform a Client Reset anyway, be sure to handle that properly instead.
My app is currently setup to handle client reset errors if an error caught by the syncManager.errorHandler is of type RLMSyncErrorClientResetError. The error in question is not of that type, so I am not currently performing a client reset.
That did not change anything. I still can’t reproduce locally.
Not sure if it is worth nothing, but this text changes for time to time when viewing the error logs.
Also, it is a possible a partial sync would be causing these errors to surface? For example, a user over a non-wifi connection cannot complete the full sync and a Sync connection was not fully established in time error is thrown. The app is now partially synced. Would that possibly cause the strange field encoding and schema change error?
Despite my app utilizing SwiftUI, would aligning with the configurations detailed in the `ViewController`` file be advised? Or, would it make sense to share more of my current configuration before doing so?