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

Immutable schema mode doesn't correctly handle changes #4901

Closed
nirinchev opened this issue Sep 12, 2021 · 4 comments
Closed

Immutable schema mode doesn't correctly handle changes #4901

nirinchev opened this issue Sep 12, 2021 · 4 comments
Assignees
Labels

Comments

@nirinchev
Copy link
Member

Expected results

Opening a readonly Realm with schema different from what is on disk should fail.

Actual Results

Realm is opened successfully and the schema on disk is used.

Steps & Code to Reproduce

  1. Open a Realm with 1 class in the schema - e.g. Foo.
  2. Open the same Realm with 2 classes - Foo and Bar and set schema_mode = SchemaMode::Immutable.
  3. Observe no error.

This appears to end up here:

case SchemaMode::Immutable:
if (version != m_schema_version)
throw InvalidSchemaVersionException(m_schema_version, version);
REALM_FALLTHROUGH;
case SchemaMode::ReadOnlyAlternative:
ObjectStore::verify_compatible_for_immutable_and_readonly(changes);
return false;

After which a lot of macro magic is happening. Ultimately, I would assume that if anything on the schema changes, OS should report that as an error. Otherwise, a user will open a Realm, happily work with it, then when they try query for Bar objects, they'd get an obscure error.

Core version

Core version: 11.4.1

@tgoyne
Copy link
Member

tgoyne commented Sep 13, 2021

This is working as intended. The idea is that only schema changes which require bumping the schema version should require regenerating your bundled Realm file, and not adding or removing types. The SDK should return a default-initialized Results (i.e. a Results in the Empty mode) for queries where the Table doesn't exist, which behaves nearly identically to a Results on an empty table.

@nirinchev
Copy link
Member Author

I'm not sure this is intuitive for users. This way we don't offer any sort of feedback that they may have a configuration error. A table being empty and a table not existing is not the same thing and it may be confusing that we're silently ignoring this particular mismatch. On the other hand, if that's the current behavior, it's likely that people haven't complained enough, so maybe that's what they want.

I'll look into aligning .net to the other SDKs.

@tgoyne
Copy link
Member

tgoyne commented Sep 13, 2021

Tables are an implementation detail, and any way to distinguish a table not existing from an empty table other than reading the schema from a file is probably a bug. Adding new types to the schema and opening a Realm silently creates the tables required, and this is just doing the same operation without actually modifying the file.

@nirinchev nirinchev self-assigned this Sep 16, 2021
@nirinchev
Copy link
Member Author

Okay, I was able to get this to work by roughly porting what Cocoa does, thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants