Skip to content

Commit ba0f15a

Browse files
authored
Properly update offline cache with latest version of the object (#1266)
* Properly update offline cache with latest version of the object * Proper name * Adds test asserting the object is properly replaced
1 parent 97e6158 commit ba0f15a

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

Parse/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import "PFAssert.h"
1616
#import "PFDecoder.h"
1717
#import "PFEncoder.h"
18+
#import "PFLogging.h"
1819
#import "PFErrorUtilities.h"
1920
#import "PFFileManager.h"
2021
#import "PFJSONSerialization.h"
@@ -1028,15 +1029,23 @@ - (void)updateObjectIdForObject:(PFObject *)object
10281029
@synchronized(self.lock) {
10291030
// See if there's already an entry for new objectId.
10301031
PFObject *existing = [self.classNameAndObjectIdToObjectMap objectForKey:key];
1031-
PFConsistencyAssert(existing == nil || existing == object,
1032-
@"Attempted to change an objectId to one that's already known to the OfflineStore. className: %@ old: %@, new: %@",
1033-
className, oldObjectId, newObjectId);
1034-
1032+
if (existing != nil && existing != object) {
1033+
PFLogError(PFLoggingTagCommon,
1034+
@"Attempted to change an objectId to one that's already known to the OfflineStore. className: %@ old: %@, new: %@",
1035+
className, oldObjectId, newObjectId);
1036+
PFLogError(PFLoggingTagCommon,
1037+
@"Set a breakpoint on PFOfflineStoreReplaceExisingObject() to debug the issue");
1038+
PFLogError(PFLoggingTagCommon,
1039+
@"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");
1040+
PFOfflineStoreReplaceExisingObject();
1041+
}
10351042
// Okay, all clear to add the new reference.
10361043
[self.classNameAndObjectIdToObjectMap setObject:object forKey:key];
10371044
}
10381045
}
10391046

1047+
void PFOfflineStoreReplaceExisingObject() {}
1048+
10401049
- (NSString *)_generateKeyForClassName:(NSString *)className
10411050
objectId:(NSString *)objectId {
10421051
return [NSString stringWithFormat:@"%@:%@", className, objectId];

Parse/Tests/Unit/QueryUnitTests.m

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,15 +1420,10 @@ - (void)testReproduceIssue1202 {
14201420
[Parse setApplicationId:@"a" clientKey:@"b"];
14211421
PFObject *objectA = [PFObject objectWithClassName:@"Object" dictionary:@{@"objectId":@"yolo", @"key": @"value"}];
14221422
objectA.objectId = @"yolo";
1423-
PFObject *objectB = [PFObject objectWithClassName:@"Object" dictionary:@{@"objectId":@"yolo", @"key": @"value"}];
1424-
@try {
1425-
objectB.objectId = @"yolo";
1426-
XCTFail();
1427-
}
1428-
@catch (NSException *e) {
1429-
XCTAssertEqual(e.name, NSInternalInconsistencyException);
1430-
XCTAssertEqualObjects(e.reason, @"Attempted to change an objectId to one that's already known to the OfflineStore. className: Object old: (null), new: yolo");
1431-
}
1423+
PFObject *objectB = [PFObject objectWithClassName:@"Object" dictionary:@{@"objectId":@"yolo", @"key": @"value2"}];
1424+
objectB.objectId = @"yolo";
1425+
PFObject *currentObject = [PFObject objectWithoutDataWithClassName:@"Object" objectId:@"yolo"];
1426+
XCTAssertEqual(currentObject[@"key"], @"value2");
14321427
}
14331428

14341429

0 commit comments

Comments
 (0)