Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyncSessionErrorCode.compensatingWrite(231) #1022

Merged
merged 6 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
* Support setting `maxNumberOfActiveVersions` when creating a `Configuration`. ([#1036](https://github.com/realm/realm-dart/pull/1036))

### Fixed
* None
* 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.

### Internal
* Using Core x.y.z.
* Using Core 12.12.0.

## 0.8.0+rc (2022-11-14)

Expand Down
9 changes: 7 additions & 2 deletions common/lib/src/realm_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 modification (UPLOAD)
compensatingWrite(231);

static final Map<int, SyncSessionErrorCode> _valuesMap = {for (var value in SyncSessionErrorCode.values) value.code: value};

Expand Down
26 changes: 26 additions & 0 deletions test/subscription_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -605,4 +606,29 @@ Future<void> main([List<String>? args]) async {
realm.close();
expect(() => subscriptions.state, throws<RealmClosedError>());
});

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<Product>(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")));
desistefanova marked this conversation as resolved.
Show resolved Hide resolved
await realm.syncSession.waitForUpload();

expect(compensatingWriteError, isA<SyncSessionError>());
final sessionError = compensatingWriteError.as<SyncSessionError>();
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);
});
}