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

SDK crashes when migrating Primary Key from String to UUID #8045

Open
koneksa-sunny opened this issue Nov 8, 2024 · 4 comments · May be fixed by #8046
Open

SDK crashes when migrating Primary Key from String to UUID #8045

koneksa-sunny opened this issue Nov 8, 2024 · 4 comments · May be fixed by #8046
Assignees

Comments

@koneksa-sunny
Copy link

koneksa-sunny commented Nov 8, 2024

SDK and version

SDK : Swift
Version: 10.33.0

Observations

  • How frequent do the crash occur? Everytime
  • Does it happen in production or during dev/test? Dev
  • Can the crash be reproduced by you? Yes
  • Can you provide instructions for how we can reproduce it? Change my primary key type from String to UUID. The migrationBlock is never called and the SDK crashes.

Crash log / stacktrace

realm-core/src/realm/object-store/shared_realm.cpp:474: [realm-core-12.13.0] Assertion failed: additive || (required_changes = ObjectStore::schema_from_group(read_group()).compare(schema)).empty()
0   RealmPackage                        0x000000010b074390 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   RealmPackage                        0x000000010b074370 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 204
2   RealmPackage                        0x000000010abf7184 _ZN5realm5Realm13update_schemaENS_6SchemaEyNSt3__18functionIFvNS2_10shared_ptrIS0_EES5_RS1_EEENS3_IFvS5_EEEb + 1680
3   RealmPackage                        0x000000010a637b18 +[RLMRealm realmWithConfiguration:queue:error:] + 2528
4   RealmPackage                        0x000000010a6db4f4 $sSo8RLMRealmC13configuration5queueABSo0A13ConfigurationC_So012OS_dispatch_C0CSgtKcfCTO + 144
5   RealmPackage                        0x000000010a791a30 $s10RealmSwift0A0V13configuration5queueA2C13ConfigurationV_So012OS_dispatch_D0CSgtKcfC + 112
6   XXXXXXX                            0x0000000102f468e4 $XXXXXXXXX + 156
7   XXXXXXX                            0x0000000102f469e0 $sIegh_IeyBh_TR + 48
8   libdispatch.dylib                   0x0000000103d64ec0 _dispatch_call_block_and_release + 24
9   libdispatch.dylib                   0x0000000103d667b8 _dispatch_client_callout + 16
10  libdispatch.dylib                   0x0000000103d6eaac _dispatch_lane_serial_drain + 912
11  libdispatch.dylib                   0x0000000103d6f7b0 _dispatch_lane_invoke + 420
12  libdispatch.dylib                   0x0000000103d7c1f0 _dispatch_root_queue_drain_deferred_wlh + 324
13  libdispatch.dylib                   0x0000000103d7b75c _dispatch_workloop_worker_thread + 732
14  libsystem_pthread.dylib             0x00000001038df814 _pthread_wqthread + 284
15  libsystem_pthread.dylib             0x00000001038de5d4 start_wqthread

Steps & Code to Reproduce

I changed my primary key type from String to UUID
OLD:

public class MyClass: Object {
  @Persisted(primaryKey: true) public var id: String?

NEW:

public class MyClass: Object {
  @Persisted(primaryKey: true) public var id: UUID?

configuration:

      schemaVersion: 3,
      migrationBlock: { migration, oldSchemaVersion in
/// THIS IS NEVER CALLED
        if oldSchemaVersion == 1 {
        } else if oldSchemaVersion == 2 {
          migration.enumerateObjects(ofType: MyClass.className()) { oldObject, newObject in
            newObject!["id"] = UUID(uuidString: oldObject!["id"]! as! String)
          }
        }
      }
Copy link

sync-by-unito bot commented Nov 8, 2024

➤ PM Bot commented:

Jira ticket: RCORE-2265

@koneksa-sunny
Copy link
Author

koneksa-sunny commented Nov 8, 2024

Note that if I change some other non-primary-key field in that class from String to UUID, I don't get the exception, but the migrationBlock is still not called and my app crashes for other reasons since it's expecting that field to be populated.

@jedelbo jedelbo self-assigned this Nov 11, 2024
@jedelbo
Copy link
Contributor

jedelbo commented Nov 11, 2024

@koneksa-sunny which SchemaMode are you using when opening the realm?

@jedelbo jedelbo linked a pull request Nov 11, 2024 that will close this issue
4 tasks
@jedelbo
Copy link
Contributor

jedelbo commented Nov 11, 2024

I found an error that would produce the issue that you report. It is fixed by #8046. But it would require that no migration function is supplied as the codeline with the assertion is only hit if there is no migration function (or if the SchemaMode is additive changes only). So in order to fix your issue, I would look for ways that the migration function could be missing in your application code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants