-
-
Notifications
You must be signed in to change notification settings - Fork 214
fix: Arrays being set as empty when calling ParseObject.clearUnsavedChanges()
#1039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This fixes the issue because the **_handleSingleResult()** function which handles the response for a single parse object in the **_ParseResponseBuilder** was calling **_notifyChildrenAboutSave();** so when **save()** was called on any object it called **_notifyChildrenAboutSaving();** first and then in the response when **_notifyChildrenAboutSave();** was called, the **_estimatedArrayBeforeSaving** had values and _savedArray was not set as empty. But in case of other queries where single object was returned like **getUpdatedUser()** or **fetch()** on any object it just called **_notifyChildrenAboutSave();** in the **_handleSingleResult()** function which resulted in **_savedArray** being set as empty since **_estimatedArrayBeforeSaving** was null. I just added the null safety and not empty check before setting the **_savedArray** to **_estimatedArrayBeforeSaving** so now the savedArray is never returned empty in the response and the issue is resolved.
|
🚀 Thanks for opening this pull request! |
|
I will reformat the title to use the proper commit message syntax. |
mbfakourii
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Could you add a test ?
|
How to do that?
…On Sat, Mar 22, 2025, 10:22 AM Mohammad Bagher Fakouri < ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Looks good. Could you add a test ?
—
Reply to this email directly, view it on GitHub
<#1039 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AY6HMS7WCHAMJBEKI3GLEKT2VTXRZAVCNFSM6AAAAABZRD7BXCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDOMBXHAZDONJQGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Please check the examples in the link below: https://github.com/parse-community/Parse-SDK-Flutter/tree/master/packages/dart/test |
|
I have seen the example. I can't seem to figure it out, I'm still a rookie developer. Can you do it yourself? |
|
When will it be merged? |
|
@nabos440 To add a test, just clone an existing test from the |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1039 +/- ##
==========================================
+ Coverage 43.75% 43.77% +0.01%
==========================================
Files 61 61
Lines 3588 3589 +1
==========================================
+ Hits 1570 1571 +1
Misses 2018 2018 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
They are failing because of codcov report upload failure and lint issue for which there is no detail as to what is causing the failure |
|
If you run |
Yes, this can be checked with the |
|
But what needs to change in the command so that it outputs the issue? |
The problem is visible in ci errors, no need to add any code. |
…-clearUnsavedChanges()-1
📝 WalkthroughWalkthroughGuards use of Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/dart/lib/src/objects/parse_array.dart (1)
69-73: Consider adding a comment to document the edge case.While the null-check is clear, a brief comment explaining why
_estimatedArrayBeforeSavingcan be null would help future maintainers. For example:// onSaved() can be called without prior onSaving() in some code paths // (e.g., getUpdatedUser(), fetch()). Skip updating _savedArray if // _estimatedArrayBeforeSaving was never initialized. if (_estimatedArrayBeforeSaving != null) { _savedArray.clear(); _savedArray.addAll(_estimatedArrayBeforeSaving!); _estimatedArrayBeforeSaving = null; }This documents the root cause and makes the defensive programming intent explicit.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/dart/lib/src/objects/parse_array.dart(1 hunks)
🔇 Additional comments (1)
packages/dart/lib/src/objects/parse_array.dart (1)
69-73: Add a test to validate the fix.The null-check logic correctly addresses the root cause and prevents
_savedArrayfrom being cleared when_estimatedArrayBeforeSavingis null. However, both the reviewer and maintainer explicitly requested adding a test to the repository to validate this fix and prevent regression.Based on the PR comments, please add a test following the patterns in
packages/dart/test. The test should:
- Simulate the scenario where
onSaved()is called without a prioronSaving()call- Verify that
savedArrayis not cleared/set to empty- Fail before your fix and pass after
If you're having difficulty writing the test, consider these steps:
- Look at existing tests in
packages/dart/testdirectory for reference- Create a test that instantiates
_ParseArray(or a Parse object with array fields)- Populate the array and manually call
onSaved()without callingonSaving()first- Assert that the array data is preserved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
packages/dart/test/src/objects/parse_object/parse_object_array_test.dart
Show resolved
Hide resolved
ParseObject.clearUnsavedChanges()
|
@nabos440 after several attempts I wasn't able to add a failing test that reproduces the issue you describe. Could you post a simple code example so we can reproduce the issue? The internal SDK flow that triggers the bug may be more complex than can be easily reproduced in my added unit test, so there root cause of the bug may be a different one and the fix in this PR may only mitigate a symptom but not patch the actual bug. |
…-clearUnsavedChanges()-1
…-clearUnsavedChanges()-1
Pull Request
Issue
Closes: #1038
Approach
Added null safety check before clearing savedArray and setting to _estimatedArrayBeforeSaving in the onSaved() function of Parse Array class
This fixes the issue because the _handleSingleResult() function which handles the response for a single parse object in the _ParseResponseBuilder was calling _notifyChildrenAboutSave(); so when save() was called on any object it called _notifyChildrenAboutSaving(); first and then in the response when _notifyChildrenAboutSave(); was called, the _estimatedArrayBeforeSaving had values and _savedArray was not set as empty.
But in case of other queries where single object was returned like getUpdatedUser() or fetch() on any object it just called _notifyChildrenAboutSave(); in the _handleSingleResult() function which resulted in _savedArray being set as empty since _estimatedArrayBeforeSaving was null. I just added the null safety check before setting the _savedArray to _estimatedArrayBeforeSaving so now the savedArray is never returned empty in the response and the issue is resolved.
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.