Closed pronebird closed 7 years ago
Things to check:
valueForKeyPath:
would convert that into NSNull
@drewmccormack I certainly can put a check for NSNulls before returning global identifiers.
Each entity implements awakeFromInsert
as suggested in your book:
- (void)awakeFromInsert {
[super awakeFromInsert];
if(!self.uniqueIdentifier) {
self.uniqueIdentifier = [[NSUUID UUID] UUIDString];
}
}
Seed database that I migrate on first run has some pre-populated data but to my understanding NSUUID
should guarantee uniqueness anyway.
Can you say anything about the relationship that caused it? Is it perhaps to a parent entity?
I guess this Ensembles v1, right? Or is it v2?
Kind regards, Drew
On 08 Mar 2016, at 16:11, Andrey Mikhaylov notifications@github.com wrote:
@drewmccormack I certainly can put a check for NSNulls before returning global identifiers.
Each entity implements awakeFromInsert as suggested in your book:
(void)awakeFromInsert { [super awakeFromInsert];
if(!self.uniqueIdentifier) { self.uniqueIdentifier = [[NSUUID UUID] UUIDString]; } } Seed database that I migrate on first run has some pre-populated data but to my understanding NSUUID should guarantee uniqueness anyway.
— Reply to this email directly or view it on GitHub.
Yes this is Ensembles v1. Relationship is one-to-one between entity A -> B with reverse one to many, so B refers to many A, while each A can only be contained within single B. I don't use parent entities and have entirely flat hierarchy.
Very odd. Anything else you can say about when it happened? What had just happened?
Otherwise it is difficult to say what could be going on.
Kind regards, Drew
On 08 Mar 2016, at 16:24, Andrey Mikhaylov notifications@github.com wrote:
Yes this is Ensembles v1. Relationship is one-to-one between entity A -> B with reverse one to many, so B refers to many A, while each A can only be contained within single B. I don't use parent entities and have entirely flat hierarchy.
— Reply to this email directly or view it on GitHub.
So I just added new object with all relationships like usual and saved it. I am trying to figure out if I can put any diagnostics in Ensembles to see any potential issues. This bug happens once in a while and does not seem to have any consequences. When I restart the app everything is fine and my records are not lost.
Do you use any extra contexts? Do you use a background context for saving?
Kind regards, Drew
On 08 Mar 2016, at 16:27, Andrey Mikhaylov notifications@github.com wrote:
So I just added new object with all relationships like usual and saved it. I am trying to figure out if I can put any diagnostics in Ensembles to see if anything caused the problem. This bug happens once in a while and does not seem to have any consequences. When I restart the app everything is fine and my records are not lost.
— Reply to this email directly or view it on GitHub.
Yes, I have root saving context running on private queue and main queue context connected to it. I merge changes to main context when private queue is saved. I also have couple of managers that monitor save events on both root context and ensembles and update certain entities in object graph if needed.
I've added check for NSNull. Will let you know if I spot anything
- (NSArray *)persistentStoreEnsemble:(CDEPersistentStoreEnsemble *)ensemble globalIdentifiersForManagedObjects:(NSArray *)objects {
NSArray *identifiers = [objects valueForKeyPath:@"uniqueIdentifier"];
[identifiers enumerateObjectsUsingBlock:^(id identifier, NSUInteger idx, BOOL *stop) {
NSAssert([[NSNull null] isEqual:identifier] == NO, @"uniqueIdentifier cannot be NSNull. Managed object: %@", objects[idx]);
}];
return identifiers;
}
You have to be very careful with a background context, because ensembles only sees the objects when you save to disk. See the book for tips. Saving and merging chapters.
Kind regards, Drew
On 08 Mar 2016, at 16:36, Andrey Mikhaylov notifications@github.com wrote:
I've added check for NSNull. Will let you know if I spot
(NSArray )persistentStoreEnsemble:(CDEPersistentStoreEnsemble )ensemble globalIdentifiersForManagedObjects:(NSArray )objects { NSArray identifiers = [objects valueForKeyPath:@"uniqueIdentifier"];
[identifiers enumerateObjectsUsingBlock:^(id identifier, NSUInteger idx, BOOL *stop) { NSAssert([[NSNull null] isEqual:identifier] == NO, @"uniqueIdentifier cannot be NSNull. Managed object: %@", objects[idx]); }];
return identifiers; } — Reply to this email directly or view it on GitHub.
I monitor root context and once it's saved I go over saved objects and index the content (e.g. tokenize), imagine blog posts and search index. Search index is then saved to CoreData too. There is no cycle because I filter out entities and properties of interest. I do the same when changes arrive from Ensembles/iCloud. I'll review my code and check your theory. I hope it's bug on my side and not in Ensembles :)
Debugger stopped today in
CDEEventBuilder
:It looked like I've got an exception or something, or maybe Xcode is under weather. Says
globalId
isNSNull
.This is the code that I use to return global IDs:
and then app enters foreground and I get this:
Each object I have in my Model implements "uniqueIdentifier" key. Any clues why that happens?`