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

Fix the exception message for refreshing an immutable Realm #5065

Merged
merged 1 commit into from
Nov 24, 2021

Conversation

ironage
Copy link
Contributor

@ironage ironage commented Nov 23, 2021

Fixes #5061

It may be debatable if calling refresh on an immutable Realm should throw or silently do nothing. We could easily make it a no-op, but it seems that the historical behaviour has been to throw an exception so I'll bring that back to not break other SDKs who may be relying on this.

Tracking down the history led to #4688 being where the first refresh was allowed and did nothing. This was because the first refresh of an immutable Realm had no associated transaction and so populated one there. The second call to refresh, now having a transaction actually tried to advance the version and the DB object throws because it has been configured without history.

☑️ ToDos

  • 📝 Changelog update
  • 🚦 Tests (or not relevant)

@ironage ironage requested review from tgoyne and nirinchev November 23, 2021 21:44
@ironage ironage self-assigned this Nov 23, 2021
@cla-bot cla-bot bot added the cla: yes label Nov 23, 2021
@@ -822,6 +822,10 @@ bool Realm::do_refresh()
return false;
}

if (m_config.immutable()) {
throw std::logic_error("Can't refresh a read-only Realm.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead return false like we do for frozen Realms?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cocoa throws an exception if the user explicitly calls refresh on an immutable Realm because it's almost certainly a sign that the developer is trying to do something that won't/can't work and we want to let them know. It makes it awkward if they write a function which accepts an arbitrary Realm and they want to call refresh() on it, but that's a terrible idea so making it awkward isn't necessarily a bad thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, but isn't it the case for frozen realms as well? I guess in my mind those two are very similar and it just triggers my OCD a little that we have different behavior here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowing calling refresh() on frozen Realms does seem like a mistake to me.

@ironage ironage merged commit d182eb3 into master Nov 24, 2021
@ironage ironage deleted the js/refresh branch November 24, 2021 00:54
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Realm::do_refresh() called twice on immutable realm throws an exception
3 participants