Skip to content

Commit 73f1044

Browse files
committed
Allowing to re-save installation if LDS is enabled
1 parent 6223d06 commit 73f1044

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
@@ -143,9 +143,7 @@ public Task<T> then(Task<Void> task) throws Exception {
143143
@Override
144144
public Task<Void> then(Task<Void> task) throws Exception {
145145
// Retry the fetch as a save operation because this Installation was deleted on the server.
146-
// Do not attempt to resave an object if LDS is enabled, since changing objectId is not allowed.
147-
if(!Parse.isLocalDatastoreEnabled()
148-
&& task.getError() != null
146+
if(task.getError() != null
149147
&& task.getError() instanceof ParseException
150148
&& ((ParseException) task.getError()).getCode() == ParseException.OBJECT_NOT_FOUND) {
151149
synchronized (mutex) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public void testImmutableKeys() {
108108

109109
@Test
110110
public void testSaveAsync() throws Exception {
111+
OfflineStore lds = new OfflineStore(RuntimeEnvironment.application);
112+
Parse.setLocalDatastore(lds);
113+
111114
String sessionToken = "sessionToken";
112115
Task<Void> toAwait = Task.forResult(null);
113116

@@ -119,11 +122,13 @@ public void testSaveAsync() throws Exception {
119122
ParseCorePlugins.getInstance()
120123
.registerCurrentInstallationController(controller);
121124
ParseObject.State state = new ParseObject.State.Builder("_Installation")
125+
.objectId("oldId")
122126
.put("deviceToken", "deviceToken")
123127
.build();
124128
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
125129
assertNotNull(installation);
126130
installation.setState(state);
131+
installation.put("key", "value");
127132

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

0 commit comments

Comments
 (0)