Skip to content

Commit ed48e36

Browse files
committed
Allowing to re-save installation if LDS is enabled
1 parent 2659e7d commit ed48e36

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Parse/src/main/java/com/parse/OfflineStore.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,17 @@ public Integer then(Task<List<T>> task) throws Exception {
14561456
if (oldObjectId.equals(newObjectId)) {
14571457
return;
14581458
}
1459-
throw new RuntimeException("objectIds cannot be changed in offline mode.");
1459+
/**
1460+
* Special case for re-saving installation if it was deleted on the server
1461+
* @see ParseInstallation#saveAsync(String, Task)
1462+
*/
1463+
if (object instanceof ParseInstallation
1464+
&& newObjectId == null) {
1465+
classNameAndObjectIdToObjectMap.remove(Pair.create(object.getClassName(), oldObjectId));
1466+
return;
1467+
} else {
1468+
throw new RuntimeException("objectIds cannot be changed in offline mode.");
1469+
}
14601470
}
14611471

14621472
String className = object.getClassName();

Parse/src/main/java/com/parse/ParseInstallation.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ public Task<T> then(Task<Void> task) throws Exception {
149149
@Override
150150
public Task<Void> then(Task<Void> task) throws Exception {
151151
// Retry the fetch as a save operation because this Installation was deleted on the server.
152-
// Do not attempt to resave an object if LDS is enabled, since changing objectId is not allowed.
153-
if(!Parse.isLocalDatastoreEnabled()
154-
&& task.getError() != null
152+
if(task.getError() != null
155153
&& task.getError() instanceof ParseException
156154
&& ((ParseException) task.getError()).getCode() == ParseException.OBJECT_NOT_FOUND) {
157155
synchronized (mutex) {

Parse/src/test/java/com/parse/ParseInstallationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ public void testInstallationObjectIdCannotBeChanged() throws Exception {
122122

123123
@Test
124124
public void testSaveAsync() throws Exception {
125+
OfflineStore lds = new OfflineStore(RuntimeEnvironment.application);
126+
Parse.setLocalDatastore(lds);
127+
125128
String sessionToken = "sessionToken";
126129
Task<Void> toAwait = Task.forResult(null);
127130

@@ -133,11 +136,13 @@ public void testSaveAsync() throws Exception {
133136
ParseCorePlugins.getInstance()
134137
.registerCurrentInstallationController(controller);
135138
ParseObject.State state = new ParseObject.State.Builder("_Installation")
139+
.objectId("oldId")
136140
.put("deviceToken", "deviceToken")
137141
.build();
138142
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
139143
assertNotNull(installation);
140144
installation.setState(state);
145+
installation.put("key", "value");
141146

142147
ParseObjectController objController = mock(ParseObjectController.class);
143148
// mock return task when Installation was deleted on the server

0 commit comments

Comments
 (0)