Uploaded image for project: 'Realm Core'
  1. Realm Core
  2. RCORE-843

Frozen realm uses the wrong schema

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      When creating a frozen realm (with sync) we are passing an empty schema in config, so the realm gets his schema from disk, and this can be different from the one that was passed by when the realm was created.
      This causes a crash in .NET when property access is attempted on a frozen object, as we rely on property indexes for that.

      This seems to be due to the fact that the schema in the config gets nulled when the schema is opened the first time:
      https://github.com/realm/realm-core/blob/680cbecf1351e04422eab5073b4dfc812e27d90c/src/realm/object-store/impl/realm_coordinator.cpp#L285-L295

      And then, when creating the frozen schema, that is still null:
      https://github.com/realm/realm-core/blob/680cbecf1351e04422eab5073b4dfc812e27d90c/src/realm/object-store/shared_realm.cpp#L890-L896

      It seems this could be fixed by setting the schema properly before creating the frozen realm like this:

      SharedRealm Realm::freeze()
      {
          auto config = m_config;
          auto version = read_transaction_version();
          config.scheduler = util::Scheduler::make_frozen(version);
          config.schema = m_schema;
          return Realm::get_frozen_realm(std::move(config), version);
      }
      

      This fixes the issue reported in .NET, but we are not sure if this is the correct way of resolving it.

            Assignee:
            thomas.goyne@mongodb.com Thomas Goyne
            Reporter:
            ferdinando.papale@mongodb.com Ferdinando Papale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: