context.parentStack == nil #238

Closed
opened 2025-12-29 15:27:12 +01:00 by adam · 20 comments
Owner

Originally created by @dufflink on GitHub (Oct 26, 2018).

Hi.
I found that in some cases in row
fetchRequest.entity = context.parentStack!.entityDescription(for: EntityIdentifier(self.entityClass))!
context.parentStack can be nil. But i dont understand why?
Can you help me?

This From.swift : 144

Originally created by @dufflink on GitHub (Oct 26, 2018). Hi. I found that in some cases in row `fetchRequest.entity = context.parentStack!.entityDescription(for: EntityIdentifier(self.entityClass))!` context.parentStack can be nil. But i dont understand why? Can you help me? This From.swift : 144
adam closed this issue 2025-12-29 15:27:12 +01:00
Author
Owner

@dufflink commented on GitHub (Oct 29, 2018):

2018-10-29 14 51 50
@dufflink commented on GitHub (Oct 29, 2018): <img width="1344" alt="2018-10-29 14 51 50" src="https://user-images.githubusercontent.com/29461219/47642350-44244e80-db8a-11e8-879f-ffa64edcb1cd.png">
Author
Owner

@dufflink commented on GitHub (Nov 2, 2018):

Please! Help me!

@dufflink commented on GitHub (Nov 2, 2018): Please! Help me!
Author
Owner

@JohnEstropia commented on GitHub (Nov 3, 2018):

@MaxPaymon Hi, can you show the code how it's being used in your app?

@JohnEstropia commented on GitHub (Nov 3, 2018): @MaxPaymon Hi, can you show the code how it's being used in your app?
Author
Owner

@JohnEstropia commented on GitHub (Nov 3, 2018):

This may also happen if the DataStack is deallocated before the objects are accessed. Is your DataStack properly retained somewhere?

@JohnEstropia commented on GitHub (Nov 3, 2018): This may also happen if the `DataStack` is deallocated before the objects are accessed. Is your `DataStack` properly retained somewhere?
Author
Owner

@evkalinin commented on GitHub (Nov 27, 2018):

Null pointer dereference is reproduced when fetching Dynamic Object from DataStack set up for managed model (NSManagedObject).

@evkalinin commented on GitHub (Nov 27, 2018): Null pointer dereference is reproduced when fetching Dynamic Object from DataStack set up for managed model (NSManagedObject).
Author
Owner

@JohnEstropia commented on GitHub (Nov 28, 2018):

@MaxPaymon Is your case just as @clouddevil stated above? If so then this is by design and I'd close this issue

@JohnEstropia commented on GitHub (Nov 28, 2018): @MaxPaymon Is your case just as @clouddevil stated above? If so then this is by design and I'd close this issue
Author
Owner

@dufflink commented on GitHub (Nov 28, 2018):

Null pointer dereference is reproduced when fetching Dynamic Object from DataStack set up for managed model (NSManagedObject).

Hi!. Do not quite understand what to do in this case.

@dufflink commented on GitHub (Nov 28, 2018): > Null pointer dereference is reproduced when fetching Dynamic Object from DataStack set up for managed model (NSManagedObject). Hi!. Do not quite understand what to do in this case.
Author
Owner

@dufflink commented on GitHub (Nov 28, 2018):

This may also happen if the DataStack is deallocated before the objects are accessed. Is your DataStack properly retained somewhere?

I call Data Stack initialization when user is authorized. I do this so that each user has his own database

2018-11-28 14 57 27
@dufflink commented on GitHub (Nov 28, 2018): > This may also happen if the `DataStack` is deallocated before the objects are accessed. Is your `DataStack` properly retained somewhere? I call Data Stack initialization when user is authorized. I do this so that each user has his own database <img width="798" alt="2018-11-28 14 57 27" src="https://user-images.githubusercontent.com/29461219/49144003-19125380-f31e-11e8-91f2-ec1a9b03af8c.png">
Author
Owner

@evkalinin commented on GitHub (Nov 28, 2018):

I have the same error when fetch DO object. Sample:
6859babd5c/CoreStoreTests/IssueTests.swift (L60)

i close https://github.com/JohnEstropia/CoreStore/issues/290, @JohnEstropia thank you

@evkalinin commented on GitHub (Nov 28, 2018): I have the same error when fetch DO object. Sample: https://github.com/clouddevil/CoreStore/blob/6859babd5c63b5dcd9d18034291d174db681c105/CoreStoreTests/IssueTests.swift#L60 i close https://github.com/JohnEstropia/CoreStore/issues/290, @JohnEstropia thank you
Author
Owner

@dufflink commented on GitHub (Nov 28, 2018):

I get it what you mean, but I am faced with the problem of implementation
2018-11-28 17 40 47

@dufflink commented on GitHub (Nov 28, 2018): I get it what you mean, but I am faced with the problem of implementation <img width="883" alt="2018-11-28 17 40 47" src="https://user-images.githubusercontent.com/29461219/49152501-db6cf500-f334-11e8-82a1-b4051b88ad76.png">
Author
Owner

@evkalinin commented on GitHub (Nov 28, 2018):

I am sure, It will be easier to answer, if you show the code sample how storage is being used in your app.

@evkalinin commented on GitHub (Nov 28, 2018): I am sure, It will be easier to answer, if you show the code sample how storage is being used in your app.
Author
Owner

@dufflink commented on GitHub (Nov 28, 2018):

2018-11-28 19 11 34 2018-11-28 19 11 44
@dufflink commented on GitHub (Nov 28, 2018): <img width="549" alt="2018-11-28 19 11 34" src="https://user-images.githubusercontent.com/29461219/49157373-78358f80-f341-11e8-93d4-4d8a211ad494.png"> <img width="618" alt="2018-11-28 19 11 44" src="https://user-images.githubusercontent.com/29461219/49157375-78ce2600-f341-11e8-90e2-f55f13571c71.png">
Author
Owner

@JohnEstropia commented on GitHub (Nov 29, 2018):

@MaxPaymon In your CacheManager class, you need to retain a strong reference to the DataStack, not the LocalStorage

@JohnEstropia commented on GitHub (Nov 29, 2018): @MaxPaymon In your `CacheManager` class, you need to retain a strong reference to the `DataStack`, not the `LocalStorage`
Author
Owner

@dufflink commented on GitHub (Nov 29, 2018):

How can i do it?

@dufflink commented on GitHub (Nov 29, 2018): How can i do it?
Author
Owner

@evkalinin commented on GitHub (Nov 29, 2018):

I try to reproduce the issue, and might be wrong.
See:
c413290adc/CoreStoreTests/IssueTests.swift (L86)
Is fetched object from different object model?

Some another question:
If has only one "Default" configuration, it must be set to nil ?
How to link application with CoreStore as static library? (without use_frameworks! in pod)

@evkalinin commented on GitHub (Nov 29, 2018): I try to reproduce the issue, and might be wrong. See: https://github.com/clouddevil/CoreStore/blob/c413290adca898891c89bd445d9665d29a6a581d/CoreStoreTests/IssueTests.swift#L86 Is fetched object from different object model? Some another question: If has only one "Default" configuration, it must be set to nil ? How to link application with CoreStore as static library? (without use_frameworks! in pod)
Author
Owner

@dufflink commented on GitHub (Nov 29, 2018):

I just need to create a separate database for each user
The application throws an error when I initialize the Storage with another name.

@dufflink commented on GitHub (Nov 29, 2018): I just need to create a separate database for each user The application throws an error when I initialize the Storage with another name.
Author
Owner

@evkalinin commented on GitHub (Nov 29, 2018):

CoreStore.defaultStack is singleton. Did you rewrite stack with last one?

@evkalinin commented on GitHub (Nov 29, 2018): CoreStore.defaultStack is singleton. Did you rewrite stack with last one?
Author
Owner

@dufflink commented on GitHub (Nov 29, 2018):

Yes

@dufflink commented on GitHub (Nov 29, 2018): Yes
Author
Owner

@JohnEstropia commented on GitHub (Dec 5, 2018):

If you require a separate store for each user, don't use CoreStore.defaultStack.
In your CacheManager, replace

private var storage: LocalStorage?

with

private var dataStack: DataStack?

and assign your DataStack there.

I'm closing this ticket as it seems to be an app-specific implementation issue. I would encourage for you to understand the relationships between DataStacks and LocalStorages, see https://github.com/JohnEstropia/CoreStore#architecture )

@JohnEstropia commented on GitHub (Dec 5, 2018): If you require a separate store for each user, don't use `CoreStore.defaultStack`. In your `CacheManager`, replace ```swift private var storage: LocalStorage? ``` with ```swift private var dataStack: DataStack? ``` and assign your `DataStack` there. I'm closing this ticket as it seems to be an app-specific implementation issue. I would encourage for you to understand the relationships between DataStacks and LocalStorages, see https://github.com/JohnEstropia/CoreStore#architecture )
Author
Owner

@dufflink commented on GitHub (Jan 10, 2019):

Здравствуйте! Я сделал, как вы советовали, но проблема осталось такой же.
2019-01-10 11 46 15

The initDB function is called every time I log in as a user.

The error occurs only when I log out from the account of one user and immediately try to log in to another user.

The place where the error most likely occurs
2019-01-10 11 52 02

@dufflink commented on GitHub (Jan 10, 2019): Здравствуйте! Я сделал, как вы советовали, но проблема осталось такой же. <img width="1072" alt="2019-01-10 11 46 15" src="https://user-images.githubusercontent.com/29461219/50951315-8218e980-14ce-11e9-8596-5aaa67972e91.png"> The initDB function is called every time I log in as a user. The error occurs only when I log out from the account of one user and immediately try to log in to another user. The place where the error most likely occurs <img width="462" alt="2019-01-10 11 52 02" src="https://user-images.githubusercontent.com/29461219/50951405-e3d95380-14ce-11e9-94c9-b71e170c2b10.png">
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#238