-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
?
-
7809
-
Not Needed
The current API for setting a mixed field in all SDKs should behave as a replace, even if the server is capable of merging lists. This is because SDKs only expose assignment operations - i.e. after:
foo.mixed = [1, 2, "abc"]
users would expect var bar = foo.mixed matches what they assigned to it, not something merged. We haven't designed an API that would allow merging, but if we did, it would look differently and be more explicit about the expected outcome - like:
var list = foo.mixed.getOrCreateList(); list.add([1, 2, "abc"]);
At the moment this test is failing
@MainActor func testAssignMixedListWithSamePrimaryKey() async throws { let realm1 = try await openRealm() let results1 = try await realm1.objects(SwiftTypesSyncObject.self).where { $0.stringCol == name }.subscribe() let realm2 = try await openRealm() let results2 = try await realm2.objects(SwiftTypesSyncObject.self).where { $0.stringCol == name }.subscribe() let primaryKey = ObjectId.generate() let object = SwiftTypesSyncObject(id: primaryKey) object.stringCol = name object.anyCol = AnyRealmValue.fromArray([.string("John")]) try realm1.write { realm1.add(object) } let object2 = SwiftTypesSyncObject(id: primaryKey) object2.stringCol = name object2.anyCol = AnyRealmValue.fromArray([.string("Marie")]) try realm2.write { realm2.add(object2) } try await realm1.syncSession?.wait(for: .upload) try await realm2.syncSession?.wait(for: .upload) try await realm1.syncSession?.wait(for: .download) try await realm2.syncSession?.wait(for: .download) XCTAssertEqual(results1.first?.anyCol.listValue?.count, 1) XCTAssertEqual(results2.first?.anyCol.listValue?.count, 1) XCTAssertEqual(results1.first?.anyCol.listValue?[0], results2.first?.anyCol.listValue?[0]) }
Even though we clear the collection before assigning to it, this is because the clear instruction is not been sent to the server.