https://supabase.com/ logo
#javascript
Title
# javascript
y

yourfriend

11/08/2021, 6:38 PM
passing
undefined
for a value of an object to be upserted doesn't seem to translate to upserting as NULL (as you might expect?) instead it doesn't bother trying to use that key value pair and so i was getting the
All object keys must match
error
was fixed by passing
null
explicitly
s

Scott P

11/08/2021, 6:44 PM
If a property in an object is undefined, most JS engines will remove the property entirely before passing it further down the stack. This is a language design choice, not an issue with the JS client itself.
y

yourfriend

11/08/2021, 6:45 PM
oh wow, didn't know that!
good lesson to learn. thanks
been writing the javascripts for a whole 6 years and never knew this haha
s

Scott P

11/08/2021, 6:49 PM
Yeah, it threw me off a few times when I was new to JS, but I believe it's done to optimise performance but also as a limitation of how memory works. Null has no value but is defined, so it can assign empty space in memory. Undefined can't be assigned to a space in memory since it's, well, not defined.
i

InASunshineState

07/06/2022, 5:37 AM
I owe you both a drink. I am never getting back four hours of my life tonight, all because I didn't realize some of my input data (which needed to be an array of some sort) was occasionally null.
As I prepped it for posting to supabase, I check quickly to see if it exists and if it doesn't just make it an empty array and that was enough for perfect upserting