Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/dart/lib/src/objects/parse_array.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ class _ParseArray implements _Valuable<List>, _ParseSaveStateAwareChild {
@mustCallSuper
void onSaved() {
setMode = false;
_savedArray.clear();
_savedArray.addAll(_estimatedArrayBeforeSaving ?? []);
_estimatedArrayBeforeSaving = null;
if (_estimatedArrayBeforeSaving != null) {
_savedArray.clear();
_savedArray.addAll(_estimatedArrayBeforeSaving!);
_estimatedArrayBeforeSaving = null;
}

if (_lastPreformedOperationBeforeSaving == lastPreformedOperation) {
// No operations were performed during the save process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,27 @@ void main() {
expect(listValue, orderedEquals([1, 2]));
});

test('Arrays should not be cleared when calling clearUnsavedChanges() '
'after fetching/querying without save', () {
// arrange - Simulate a fetch/query response (no prior save operation)
dietPlansObject.fromJson({
keyArray: [1, 2, 3],
"objectId": "someId",
}); // assume this coming from the server via fetch/query

// Simulate what happens in _handleSingleResult for fetch/query
// (calls _notifyChildrenAboutSave without prior _notifyChildrenAboutSaving)
// This reproduces the bug where arrays were incorrectly cleared
dietPlansObject._notifyChildrenAboutSave();

// act - this should NOT clear the arrays
dietPlansObject.clearUnsavedChanges();

// assert - arrays should still have their values
final listValue = dietPlansObject.get(keyArray);
expect(listValue, orderedEquals([1, 2, 3]));
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.

test('The list value and the value for api request should be identical '
'before and after the save() failed to save the object', () async {
// arrange
Expand Down