Open joaocolaco opened 2 years ago
@tgoyne I don't know if this is the intended behaviour for a read only realm, and the use case is to be able to use the realm in another thread. I have the following test, which reproduce the issue,
func testFreezeReadOnlyRealm() throws {
try autoreleasepool {
let realm = try Realm()
let frozenRealm = realm.freeze()
XCTAssert(frozenRealm.isFrozen)
}
var configuration = Realm.Configuration.defaultConfiguration
configuration.readOnly = true
let realm = try Realm(configuration: configuration)
let frozenRealm = realm.freeze()
XCTAssert(frozenRealm.isFrozen) // This is failing
}
Seems like the realm cannot be freeze because it doesn't have a version, but I don't know the intended behaviour behind it.
Read-only Realms should probably always just report isFrozen
since they behave like frozen Realms and if we did that they'd become safe to use across threads.
And that would also simplify a bit of my code (and whoever uses this functionality).
What's the workaround for this bug? I don't quite understand but just realized after a day's effort that this is a library bug that I'm also hitting. Thanks
Ah the OP has a typo, readOnly should be false
@jedelbo I think this will be a quick fix on OS, checking if the realm is readOnly
and always return isFrozen true
, then it would be safe to use the realm across threads.
The workaround stopped working for me: now when I remove readOnly: true, it complains about not being able to create the .lock file inside the Bundle path.
Bumping this issue - I still run into the above. Thanks
Hi.
It seems the #7697 bug resurfaces when freezing a realm opened as read-only. In my case calling
freeze()
in a realm returns exactly the same realm (that also returns false to.isFrozen
). ChangingreadOnly
to true in the realm configuration makesfreeze()
work again.Can this bug be fixed?
@dianaafanador3 has already done an repo test in https://github.com/realm/realm-swift/issues/7697#issuecomment-1178911563_
Originally posted by @joaocolaco in https://github.com/realm/realm-swift/issues/7697#issuecomment-1175366173
Edit with use case from https://github.com/realm/realm-swift/issues/7697#issuecomment-1179015318: