File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -1456,7 +1456,17 @@ public Integer then(Task<List<T>> task) throws Exception {
1456
1456
if (oldObjectId .equals (newObjectId )) {
1457
1457
return ;
1458
1458
}
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
+ }
1460
1470
}
1461
1471
1462
1472
String className = object .getClassName ();
Original file line number Diff line number Diff line change @@ -149,9 +149,7 @@ public Task<T> then(Task<Void> task) throws Exception {
149
149
@ Override
150
150
public Task <Void > then (Task <Void > task ) throws Exception {
151
151
// 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
155
153
&& task .getError () instanceof ParseException
156
154
&& ((ParseException ) task .getError ()).getCode () == ParseException .OBJECT_NOT_FOUND ) {
157
155
synchronized (mutex ) {
Original file line number Diff line number Diff line change @@ -122,6 +122,9 @@ public void testInstallationObjectIdCannotBeChanged() throws Exception {
122
122
123
123
@ Test
124
124
public void testSaveAsync () throws Exception {
125
+ OfflineStore lds = new OfflineStore (RuntimeEnvironment .application );
126
+ Parse .setLocalDatastore (lds );
127
+
125
128
String sessionToken = "sessionToken" ;
126
129
Task <Void > toAwait = Task .forResult (null );
127
130
@@ -133,11 +136,13 @@ public void testSaveAsync() throws Exception {
133
136
ParseCorePlugins .getInstance ()
134
137
.registerCurrentInstallationController (controller );
135
138
ParseObject .State state = new ParseObject .State .Builder ("_Installation" )
139
+ .objectId ("oldId" )
136
140
.put ("deviceToken" , "deviceToken" )
137
141
.build ();
138
142
ParseInstallation installation = ParseInstallation .getCurrentInstallation ();
139
143
assertNotNull (installation );
140
144
installation .setState (state );
145
+ installation .put ("key" , "value" );
141
146
142
147
ParseObjectController objController = mock (ParseObjectController .class );
143
148
// mock return task when Installation was deleted on the server
You can’t perform that action at this time.
0 commit comments