File tree 3 files changed +17
-4
lines changed
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 @@ -143,9 +143,7 @@ public Task<T> then(Task<Void> task) throws Exception {
143
143
@ Override
144
144
public Task <Void > then (Task <Void > task ) throws Exception {
145
145
// 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
149
147
&& task .getError () instanceof ParseException
150
148
&& ((ParseException ) task .getError ()).getCode () == ParseException .OBJECT_NOT_FOUND ) {
151
149
synchronized (mutex ) {
Original file line number Diff line number Diff line change @@ -108,6 +108,9 @@ public void testImmutableKeys() {
108
108
109
109
@ Test
110
110
public void testSaveAsync () throws Exception {
111
+ OfflineStore lds = new OfflineStore (RuntimeEnvironment .application );
112
+ Parse .setLocalDatastore (lds );
113
+
111
114
String sessionToken = "sessionToken" ;
112
115
Task <Void > toAwait = Task .forResult (null );
113
116
@@ -119,11 +122,13 @@ public void testSaveAsync() throws Exception {
119
122
ParseCorePlugins .getInstance ()
120
123
.registerCurrentInstallationController (controller );
121
124
ParseObject .State state = new ParseObject .State .Builder ("_Installation" )
125
+ .objectId ("oldId" )
122
126
.put ("deviceToken" , "deviceToken" )
123
127
.build ();
124
128
ParseInstallation installation = ParseInstallation .getCurrentInstallation ();
125
129
assertNotNull (installation );
126
130
installation .setState (state );
131
+ installation .put ("key" , "value" );
127
132
128
133
ParseObjectController objController = mock (ParseObjectController .class );
129
134
// mock return task when Installation was deleted on the server
You can’t perform that action at this time.
0 commit comments