-
Notifications
You must be signed in to change notification settings - Fork 73
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
Fix: SQLite causes crash when trying to merge undefined #334
Fix: SQLite causes crash when trying to merge undefined #334
Conversation
@tgolen what's the desired behaviour of Onyx if a key is set to Should we also remove the key when setting/merging |
lib/Onyx.js
Outdated
if (_.isObject(existingValue) || _.isObject(lastChange)) { | ||
// We want to merge multiple object delates together | ||
// If all of the changes are objects, we can simply merge all of them together | ||
// If the batched changes contain nullish values or arrays, we should only merge the very last objects in the batch |
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.
Can you please expand this comment to explain why only the last objects in the batch should be merged? I'm not sure I understand the scenario or what nullish and array values have to do with it.
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.
+1
May be we want to merge the very last value in the batch - irrespective of if it is null or not null
lib/utils.js
Outdated
@@ -0,0 +1,13 @@ | |||
function countObjectsAtEndOfArray(array) { |
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.
I'm not quite getting this... what about objects at the beginning or the middle of the array?
I don't think we should do that. Just throw the value out. Probably they wanted to merge something. Not delete it and it just happened to be |
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.
I think this new behavior is not desirable. I propose we ignore any merging of undefined
values. We never said anywhere that you can do this. People might not intentionally be doing this. It is much more likely that a value would be unintentionally undefined
than unintentionally null
.
Alright 👍 Makes sense! Just wanted to be on the same page on that. Will instead just set the value to |
Please wait with reviews, fixing tests right now... |
@tgolen @marcaaron i moved the improvements i made to a separate PR, as this became kind of a scope creep already. |
This PR now only contains the lines of code needed in |
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.
Thanks for decreasing the scope of this!
@tgolen @marcaaron
Details
When you run
Onyx.merge
with the valueundefined
on native platforms, SQLite will crash the app, because we have aNOT NULL
constraint for all values in the database.Proposal
When
undefined
is passed as the value inOnyx.merge
we manually remove the key from storage withStorage.removeItem
and remove it from the merge delta.Related Issues
https://expensify.slack.com/archives/C01GTK53T8Q/p1693404147209609
Automated Tests
Linked PRs