From 531b6af7cff2afbae04cd2daeb4509ff89790313 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Thu, 10 Nov 2022 23:49:16 +0200 Subject: [PATCH 1/5] Add compensatingWrite error to SyncSessionErrorCode --- common/lib/src/realm_types.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common/lib/src/realm_types.dart b/common/lib/src/realm_types.dart index 0f60d47c0..707c9bd4b 100644 --- a/common/lib/src/realm_types.dart +++ b/common/lib/src/realm_types.dart @@ -424,8 +424,13 @@ enum SyncSessionErrorCode { /// Client tried to open a session before initial sync is complete (BIND) initialSyncNotCompleted(229), - /// Client attempted a write that is disallowed by permissions, or modifies an object outside the current query - requires client reset (UPLOAD) - writeNotAllowed(230); + /// Client attempted a write that is disallowed by permissions, or modifies an object + /// outside the current query - requires client reset (UPLOAD) + writeNotAllowed(230), + + /// Client attempted a write that is disallowed by permissions, or modifies an object + /// outside the current query, and the server undid the modificatio (UPLOAD) + compensatingWrite(231); static final Map _valuesMap = {for (var value in SyncSessionErrorCode.values) value.code: value}; From 9158463b4e2d0590d04e051622e00aaea5a9bb76 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Fri, 11 Nov 2022 00:03:46 +0200 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + common/lib/src/realm_types.dart | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8700f25e6..6ff1363d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixed * Allow backlinks between files. ([#1015](https://github.com/realm/realm-dart/issues/1015)) * Fix issue with accessing properties after traversing a backlink. ([#1018](https://github.com/realm/realm-dart/issues/1018)) +* Support mapping into `SyncSessionErrorCode` for "Compensating write" with error code 231. ([#1022](https://github.com/realm/realm-dart/pull/1022)) ### Compatibility * Realm Studio: 12.0.0 or later. diff --git a/common/lib/src/realm_types.dart b/common/lib/src/realm_types.dart index 707c9bd4b..07435e0d8 100644 --- a/common/lib/src/realm_types.dart +++ b/common/lib/src/realm_types.dart @@ -429,7 +429,7 @@ enum SyncSessionErrorCode { writeNotAllowed(230), /// Client attempted a write that is disallowed by permissions, or modifies an object - /// outside the current query, and the server undid the modificatio (UPLOAD) + /// outside the current query, and the server undid the modification (UPLOAD) compensatingWrite(231); static final Map _valuesMap = {for (var value in SyncSessionErrorCode.values) value.code: value}; From 68cb98337dc98bbd72308089264319cd5a05079e Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Tue, 15 Nov 2022 12:20:37 +0200 Subject: [PATCH 3/5] Using Core 12.12.0. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e06868549..1f89cf698 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ * Realm Studio: 12.0.0 or later. ### Internal -* Using Core x.y.z. +* Using Core 12.12.0. ## 0.8.0+rc (2022-11-14) From b11c9a20afaeaeaa4aef9fba532202f8f0a8fe32 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Tue, 15 Nov 2022 13:21:42 +0200 Subject: [PATCH 4/5] Test compensatingWrite --- test/subscription_test.dart | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/subscription_test.dart b/test/subscription_test.dart index b0cf31bb2..5fe3503c2 100644 --- a/test/subscription_test.dart +++ b/test/subscription_test.dart @@ -27,6 +27,7 @@ import '../lib/realm.dart'; import '../lib/src/configuration.dart'; import '../lib/src/native/realm_core.dart'; import '../lib/src/subscription.dart'; +import 'client_reset_test.dart'; import 'test.dart'; @isTest @@ -605,4 +606,29 @@ Future main([List? args]) async { realm.close(); expect(() => subscriptions.state, throws()); }); + + baasTest('SyncSessionErrorCode.compensatingWrite', (configuration) async { + late SyncError compensatingWriteError; + final productNamePrefix = generateRandomString(4); + final app = App(configuration); + final user = await getIntegrationUser(app); + final config = Configuration.flexibleSync(user, [Product.schema], syncErrorHandler: (syncError) { + compensatingWriteError = syncError; + }); + final realm = getRealm(config); + final query = realm.query(r'stringQueryField BEGINSWITH $0', [productNamePrefix]); + if (realm.subscriptions.find(query) == null) { + realm.subscriptions.update((mutableSubscriptions) => mutableSubscriptions.add(query)); + } + await realm.subscriptions.waitForSynchronization(); + realm.write(() => realm.add(Product(ObjectId(), "doen't match subscription"))); + await realm.syncSession.waitForUpload(); + + expect(compensatingWriteError, isA()); + final sessionError = compensatingWriteError.as(); + expect(sessionError.category, SyncErrorCategory.session); + expect(sessionError.isFatal, false); + expect(sessionError.code, SyncSessionErrorCode.compensatingWrite); + expect(sessionError.message!.startsWith('Client attempted a write that is outside of permissions or query filters'), isTrue); + }); } From 5f4ec0697a2c60bd07e11f579a3124a033eb8638 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova <95419820+desistefanova@users.noreply.github.com> Date: Tue, 15 Nov 2022 14:03:09 +0200 Subject: [PATCH 5/5] Update test/subscription_test.dart Co-authored-by: Nikola Irinchev --- test/subscription_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/subscription_test.dart b/test/subscription_test.dart index 5fe3503c2..f1f55c672 100644 --- a/test/subscription_test.dart +++ b/test/subscription_test.dart @@ -621,7 +621,7 @@ Future main([List? args]) async { realm.subscriptions.update((mutableSubscriptions) => mutableSubscriptions.add(query)); } await realm.subscriptions.waitForSynchronization(); - realm.write(() => realm.add(Product(ObjectId(), "doen't match subscription"))); + realm.write(() => realm.add(Product(ObjectId(), "doesn't match subscription"))); await realm.syncSession.waitForUpload(); expect(compensatingWriteError, isA());