diff --git a/Parse/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m b/Parse/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m index f178dd32d..4ff79b01a 100644 --- a/Parse/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m +++ b/Parse/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m @@ -15,6 +15,7 @@ #import "PFAssert.h" #import "PFDecoder.h" #import "PFEncoder.h" +#import "PFLogging.h" #import "PFErrorUtilities.h" #import "PFFileManager.h" #import "PFJSONSerialization.h" @@ -1028,15 +1029,23 @@ - (void)updateObjectIdForObject:(PFObject *)object @synchronized(self.lock) { // See if there's already an entry for new objectId. PFObject *existing = [self.classNameAndObjectIdToObjectMap objectForKey:key]; - PFConsistencyAssert(existing == nil || existing == object, - @"Attempted to change an objectId to one that's already known to the OfflineStore. className: %@ old: %@, new: %@", - className, oldObjectId, newObjectId); - + if (existing != nil && existing != object) { + PFLogError(PFLoggingTagCommon, + @"Attempted to change an objectId to one that's already known to the OfflineStore. className: %@ old: %@, new: %@", + className, oldObjectId, newObjectId); + PFLogError(PFLoggingTagCommon, + @"Set a breakpoint on PFOfflineStoreReplaceExisingObject() to debug the issue"); + PFLogError(PFLoggingTagCommon, + @"Starting 1.17.0, the new object will replace the old one, if this is causing unexpected behaviours, please open an issue https://github.com/parse-community/Parse-SDK-iOS-OSX/issues/new"); + PFOfflineStoreReplaceExisingObject(); + } // Okay, all clear to add the new reference. [self.classNameAndObjectIdToObjectMap setObject:object forKey:key]; } } +void PFOfflineStoreReplaceExisingObject() {} + - (NSString *)_generateKeyForClassName:(NSString *)className objectId:(NSString *)objectId { return [NSString stringWithFormat:@"%@:%@", className, objectId]; diff --git a/Parse/Tests/Unit/QueryUnitTests.m b/Parse/Tests/Unit/QueryUnitTests.m index a1da7d8c4..a9ccda784 100644 --- a/Parse/Tests/Unit/QueryUnitTests.m +++ b/Parse/Tests/Unit/QueryUnitTests.m @@ -1420,15 +1420,10 @@ - (void)testReproduceIssue1202 { [Parse setApplicationId:@"a" clientKey:@"b"]; PFObject *objectA = [PFObject objectWithClassName:@"Object" dictionary:@{@"objectId":@"yolo", @"key": @"value"}]; objectA.objectId = @"yolo"; - PFObject *objectB = [PFObject objectWithClassName:@"Object" dictionary:@{@"objectId":@"yolo", @"key": @"value"}]; - @try { - objectB.objectId = @"yolo"; - XCTFail(); - } - @catch (NSException *e) { - XCTAssertEqual(e.name, NSInternalInconsistencyException); - XCTAssertEqualObjects(e.reason, @"Attempted to change an objectId to one that's already known to the OfflineStore. className: Object old: (null), new: yolo"); - } + PFObject *objectB = [PFObject objectWithClassName:@"Object" dictionary:@{@"objectId":@"yolo", @"key": @"value2"}]; + objectB.objectId = @"yolo"; + PFObject *currentObject = [PFObject objectWithoutDataWithClassName:@"Object" objectId:@"yolo"]; + XCTAssertEqual(currentObject[@"key"], @"value2"); }