Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Parse/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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];
Expand Down
13 changes: 4 additions & 9 deletions Parse/Tests/Unit/QueryUnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}


Expand Down