Context does not save the changes with error 1550

2019-02-25 08:32发布

问题:

I'm trying to update an entity and save the changes. I'm getting always the following error:

The operation couldn’t be completed. (Cocoa error 1550.)

Method:

- (BOOL) updateEvent:(EventDTO*)eventDTO{
    BOOL saved = YES;

    [self getDataCoreContext];

    if (context) {
        NSError *error;

        Event *myEvent = (Event *)[context existingObjectWithID:eventDTO.entitysID error:&error];

        myEvent.name = eventDTO.name;
        myEvent.descrptn = eventDTO.description;
        myEvent.date = eventDTO.date;
        myEvent.locLatitude = [eventDTO getLatidude];
        myEvent.locLongitude = [eventDTO getLongitude];
        myEvent.numberOfInvited= [NSNumber numberWithInteger:[eventDTO.invitedMembers count]];

        for (User *invUser in eventDTO.invitedMembers) {
            [myEvent addInvitedUsersObject:invUser];
        }

        for (User *accUser in eventDTO.acceptedMembers) {
            [myEvent addAcceptedUsersObject:accUser];
        }

        myEvent.createdBy = (User*)[context existingObjectWithID:eventDTO.creator.objectID error:&error];

        if (![context save:&error]) {
            NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
            saved = NO;
        }
    }
    return saved;
}

Its confusing me really, because i m not getting it what the problem is.. I have also tried to fetch the object and modify it. But same error.

Any explanation or hints would be great.

EDIT (Complete Error Object) 1:

ERROR: Error Domain=NSCocoaErrorDomain Code=1550 "The operation couldn’t be completed. (Cocoa error 1550.)" UserInfo=0x14a00130 {NSValidationErrorObject=<Event: 0x11024aa0> (entity: Event; id: 0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8> ; data: {
    acceptedUsers =     (
    );
    createdBy = "0x11024ae0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p1>";
    date = "2013-05-11 16:15:09 +0000";
    descrptn = Auauuauau;
    invitedUsers =     (
        "0x11069cd0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p3>",
        "0x1104da60 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p6>",
        "0x1104da40 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p4>",
        "0x110687a0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p2>",
        "0x1104da50 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p5>"
    );
    locLatitude = "51.45373916625977";
    locLongitude = "7.264190196990967";
    name = lALLALLa;
    numberOfInvited = 5;
}), NSValidationErrorKey=invitedUsers, NSLocalizedDescription=The operation couldn’t be completed. (Cocoa error 1550.), NSValidationErrorValue=Relationship 'invitedUsers' on managed object (0x11024aa0) <Event: 0x11024aa0> (entity: Event; id: 0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8> ; data: {
    acceptedUsers =     (
    );
    createdBy = "0x11024ae0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p1>";
    date = "2013-05-11 16:15:09 +0000";
    descrptn = Auauuauau;
    invitedUsers =     (
        "0x11069cd0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p3>",
        "0x1104da60 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p6>",
        "0x1104da40 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p4>",
        "0x110687a0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p2>",
        "0x1104da50 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p5>"
    );
    locLatitude = "51.45373916625977";
    locLongitude = "7.264190196990967";
    name = lALLALLa;
    numberOfInvited = 5;
}) with objects {(
    <User: 0x110accb0> (entity: User; id: 0x11069cd0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p3> ; data: {
    acceptedEvents = "<relationship fault: 0x97084a0 'acceptedEvents'>";
    createdEvents = "<relationship fault: 0x97017b0 'createdEvents'>";
    deviceInfo = nil;
    displayName = "Daniel Higgins";
    invitedToEvents =     (
        "0x110abbb0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x110abba0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p5>"
    );
    memberShipDetails = nil;
    phoneNumber = "555-478-7672";
    realName = "Daniel Higgins";
    status = "WAZZUUP?!";
    userID = nil;
}),
    <User: 0x110d0e10> (entity: User; id: 0x1104da60 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p6> ; data: {
    acceptedEvents = "<relationship fault: 0x14aa0850 'acceptedEvents'>";
    createdEvents = "<relationship fault: 0x13c0f290 'createdEvents'>";
    deviceInfo = nil;
    displayName = "Hank Zakroff";
    invitedToEvents =     (
        "0x110abbb0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x110abba0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p5>"
    );
    memberShipDetails = nil;
    phoneNumber = "(555) 766-4823";
    realName = "Hank Zakroff";
    status = "WAZZUUP?!";
    userID = nil;
}),
    <User: 0x110ad1a0> (entity: User; id: 0x1104da40 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p4> ; data: {
    acceptedEvents = "<relationship fault: 0x16632850 'acceptedEvents'>";
    createdEvents = "<relationship fault: 0x16632890 'createdEvents'>";
    deviceInfo = nil;
    displayName = "John Appleseed";
    invitedToEvents =     (
        "0x110abbb0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x110abba0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p5>"
    );
    memberShipDetails = nil;
    phoneNumber = "888-555-5512";
    realName = "John Appleseed";
    status = "WAZZUUP?!";
    userID = nil;
}),
    <User: 0x110b3220> (entity: User; id: 0x110687a0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p2> ; data: {
    acceptedEvents = "<relationship fault: 0x110f50f0 'acceptedEvents'>";
    createdEvents = "<relationship fault: 0x16628a60 'createdEvents'>";
    deviceInfo = nil;
    displayName = "Kate Bell";
    invitedToEvents =     (
        "0x110abbb0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x110abba0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p5>"
    );
    memberShipDetails = nil;
    phoneNumber = "(555) 564-8583";
    realName = "Kate Bell";
    status = "WAZZUUP?!";
    userID = nil;
}),
    <User: 0x110ace30> (entity: User; id: 0x1104da50 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p5> ; data: {
    acceptedEvents = "<relationship fault: 0x1a4c6350 'acceptedEvents'>";
    createdEvents = "<relationship fault: 0x1a4c6390 'createdEvents'>";
    deviceInfo = nil;
    displayName = "Anna Haro";
    invitedToEvents =     (
        "0x110abbb0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x110abba0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p5>"
    );
    memberShipDetails = nil;
    phoneNumber = "555-522-8243";
    realName = "Anna Haro";
    status = "WAZZUUP?!";
    userID = nil;
})
)}}

EDIT 2:

According to the nice explanation of @Sulthan i found the Problem.

In my for loops i had to check if this User already exist in that Event:

for (User *invUser in eventDTO.invitedMembers) {
    BOOL existsInInvitedList = [[eventDTO.invitedMembers valueForKeyPath:@"objectID"] containsObject:invUser.objectID];
    if (!existsInInvitedList) {
        [myEvent addInvitedUsersObject:invUser];
    }
}


for (User *accUser in eventDTO.acceptedMembers) {
    BOOL existsInAcceptedList = [[eventDTO.acceptedMembers valueForKeyPath:@"objectID"] containsObject:accUser.objectID];
    if (!existsInAcceptedList) {
        [myEvent addAcceptedUsersObject:accUser];
    }
}

So there were no duplicates in there..

回答1:

Explanation:

NSValidationErrorObject=<Event: 0x11024aa0> ...

This is the object that you trying to save and validation failed for it

NSValidationErrorKey=invitedUsers

This is the attribute (relationship) that failed validation

NSValidationErrorValue=Relationship 'invitedUsers' on managed object (0x11024aa0)

What failed validation. Everything else is the list of the users in the relationship...

I don't know your object model but for example the following seems to be wrong:

invitedToEvents =     (
        "0x110abbb0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x110abba0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p5>"
    );

Note that one of the events is there twice (it has the same object id).



回答2:

Cocoa error 1550 means you are having a "dangling" pointer, more specifically a reference to a relationship that points to nowhere... I would assume you might be getting a nil back from one of the existinObjectWithID methods?



回答3:

I ran into the 1550 error code as well. I had accidentally changed the data model and modified the destination of one of the relationships in an entity. Make sure to double check that the entity described by NSValidationErrorObject and the relationship described by NSValidationErrorKey are what you intend them to be.