Originally created by @spacedema on GitHub (May 21, 2020).
Hi!
Noticed strange behaviour while fetching from db, don't know if it is related to core store
```
// Ok
func getSomeId() -> String? {
let transaction = DataStack.beginUnsafe()
return try? transaction.fetchOne(From<Users>().where(\.id == myId))?.otherField?.id
}
// Not Ok, return nil
func getSomeId() -> String? {
return try? DataStack.beginUnsafe().fetchOne(From<Users>().where(\.id == myId))?.otherField?.id
}
```
adam
added the question label 2025-12-29 18:25:44 +01:00
My guess it that ARC releases the transaction earlier in the second code. If that's the case, you will probably experience the same thing in the first code when building release (optimized) builds.
@JohnEstropia commented on GitHub (May 22, 2020):
My guess it that ARC releases the transaction earlier in the second code. If that's the case, you will probably experience the same thing in the first code when building release (optimized) builds.
You can try
```swift
return withExtendedLIfetime(DataStack.beginUnsafe()) { transaction in
try? transaction.fetchOne(From<Users>().where(\.id == myId))?.otherField?.id
}
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @spacedema on GitHub (May 21, 2020).
Hi!
Noticed strange behaviour while fetching from db, don't know if it is related to core store
@JohnEstropia commented on GitHub (May 22, 2020):
My guess it that ARC releases the transaction earlier in the second code. If that's the case, you will probably experience the same thing in the first code when building release (optimized) builds.
You can try
@spacedema commented on GitHub (May 22, 2020):
Thanks for the answer, will check it in release build