Skip to content

Commit 04f763c

Browse files
authoredMar 23, 2023
fix: Attempt to save ParseObject even if its nested ParseObject failed to save (#859)
1 parent bdbc483 commit 04f763c

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed
 

‎packages/dart/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [4.0.2](https://github.com/parse-community/Parse-SDK-Flutter/compare/dart-4.0.1...dart-4.0.2) (2023-03-23)
2+
3+
### Bug Fixes
4+
5+
* Attempt to save `ParseObject` even if its nested `ParseObject` failed to save ([#859](https://github.com/parse-community/Parse-SDK-Flutter/pull/859))
6+
17
## [4.0.1](https://github.com/parse-community/Parse-SDK-Flutter/compare/dart-4.0.0...dart-4.0.1) (2023-03-20)
28

39
### Bug Fixes

‎packages/dart/lib/src/base/parse_constants.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
part of flutter_parse_sdk;
22

33
// Library
4-
const String keySdkVersion = '4.0.1';
4+
const String keySdkVersion = '4.0.2';
55
const String keyLibraryName = 'Flutter Parse SDK';
66

77
// End Points

‎packages/dart/lib/src/objects/parse_object.dart

+18
Original file line numberDiff line numberDiff line change
@@ -138,34 +138,42 @@ class ParseObject extends ParseBase implements ParseCloneable {
138138
final ParseResponse response = ParseResponse();
139139
return response;
140140
}
141+
141142
if (object is ParseObject) {
142143
uniqueObjects.remove(object);
143144
}
145+
144146
for (ParseFileBase file in uniqueFiles) {
145147
final ParseResponse response = await file.save();
146148
if (!response.success) {
147149
return response;
148150
}
149151
}
152+
150153
List<ParseObject> remaining = uniqueObjects.toList();
151154
final List<ParseObject> finished = <ParseObject>[];
155+
152156
final ParseResponse totalResponse = ParseResponse()
153157
..success = true
154158
..results = <dynamic>[]
155159
..statusCode = 200;
160+
156161
while (remaining.isNotEmpty) {
157162
/* Partition the objects into two sets: those that can be save immediately,
158163
and those that rely on other objects to be created first. */
159164
final List<ParseObject> current = <ParseObject>[];
160165
final List<ParseObject> nextBatch = <ParseObject>[];
166+
161167
for (ParseObject object in remaining) {
162168
if (object._canbeSerialized(finished)) {
163169
current.add(object);
164170
} else {
165171
nextBatch.add(object);
166172
}
167173
}
174+
168175
remaining = nextBatch;
176+
169177
// TODO(yulingtianxia): lazy User
170178
/* Batch requests have currently a limit of 50 packaged requests per single request
171179
This splitting will split the overall array into segments of upto 50 requests
@@ -179,6 +187,7 @@ class ParseObject extends ParseBase implements ParseCloneable {
179187
final List<dynamic> requests = chunk.map<dynamic>((ParseObject obj) {
180188
return obj._getRequestJson(obj.objectId == null ? 'POST' : 'PUT');
181189
}).toList();
190+
182191
for (ParseObject obj in chunk) {
183192
obj._saveChanges();
184193
}
@@ -188,13 +197,19 @@ class ParseObject extends ParseBase implements ParseCloneable {
188197
client: _client,
189198
);
190199
totalResponse.success &= response.success;
200+
191201
if (response.success) {
192202
totalResponse.results!.addAll(response.results!);
193203
totalResponse.count += response.count;
204+
194205
for (int i = 0; i < response.count; i++) {
195206
if (response.results![i] is ParseError) {
196207
// Batch request succeed, but part of batch failed.
197208
chunk[i]._revertSavingChanges();
209+
210+
// if any request in a batch requests group fails,
211+
// then the overall response will be considered unsuccessful.
212+
totalResponse.success = false;
198213
} else {
199214
chunk[i]._savingChanges.clear();
200215
}
@@ -204,12 +219,15 @@ class ParseObject extends ParseBase implements ParseCloneable {
204219
for (ParseObject obj in chunk) {
205220
obj._revertSavingChanges();
206221
}
222+
207223
totalResponse.statusCode = response.statusCode;
208224
totalResponse.error = response.error;
209225
}
210226
}
227+
211228
finished.addAll(current);
212229
}
230+
213231
return totalResponse;
214232
}
215233

‎packages/dart/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: parse_server_sdk
22
description: Dart plugin for Parse Server, (https://parseplatform.org), (https://back4app.com)
3-
version: 4.0.1
3+
version: 4.0.2
44
homepage: https://github.com/parse-community/Parse-SDK-Flutter
55

66
environment:

‎packages/dart/test/src/objects/parse_object/parse_object_save_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,6 @@ void main() {
481481

482482
verifyNoMoreInteractions(client);
483483
},
484-
skip: 'see #853 and #854',
485484
);
486485
});
487486
}

0 commit comments

Comments
 (0)