set/update object with undefined children fails. why?

5,832 views
Skip to first unread message

Jonathan Friedman

unread,
Jul 8, 2013, 8:15:51 PM7/8/13
to fireba...@googlegroups.com
You get the following error when you try to set or update a reference with an object that contains undefined children:

Error: Firebase.set failed: First argument contains undefined in property '-Iz-kNziy1_NdpbJ_2f7.response.errors'

the object looks like this:

{"-Iz-kNziy1_NdpbJ_2f7": {"some_property": 123, "response": {"errors": undefined, "data": 123}}}

Seems to me that this should be ignored or handled silently. It's simply not an error. It doesn't represent any critical condition, nor should it violate any expressed Firebase behaviors.

Set reference to this value means take what I give you and express it in the data store. 

Update reference to this value means take what I give you and change the state of the specified properties to the specified values.

What am I missing here?

Cheers,
-Jonathan

Jonathan Friedman, PhD
CircuitHub, Inc.

Andrew Lee

unread,
Jul 8, 2013, 8:21:03 PM7/8/13
to fireba...@googlegroups.com
Jonathan -

The issue here is that 'undefined' is not a type in JSON, and it's not something that Firebase can store. 

We *could* just treat an "undefined" as null and just delete / ignore it, but in our experience most of the time when there's an undefined in an object it's indicative of a bug in someone's code. In this case, they'd prefer to see an error rather than simply have their data disappear.

Since we're a database, we try to err on the side of consistency / no data loss when these sorts of things come up.

-Andrew


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Andrew Lee
Founder, Firebase
http://twitter.com/startupandrew

Jonathan Friedman

unread,
Jul 8, 2013, 8:28:16 PM7/8/13
to fireba...@googlegroups.com
Fair enough. Makes sense. Didn't try to use null! Oops. So simple fix...

if errors? then errors else null

Works for me. On to the next bug in my code... ;-)

Thanks again.

Cheers,
-Jonathan
Reply all
Reply to author
Forward
0 new messages