firebase-functions-python icon indicating copy to clipboard operation
firebase-functions-python copied to clipboard

Mimic behavior from Node.js on KeyError

Open Zaffer opened this issue 8 months ago • 2 comments

When a field does not exist on a document, the Python Cloud Function throws an error KeyError, but for the Node.js implementation it simply returns undefined (preferred). This is especially important for the on_document_written function, which might trigger for updates that need to be monitored, but if the document is created for the first time without fields yet, then this should not throw an error ideally.

Zaffer avatar Apr 20 '25 04:04 Zaffer

Hi @Zaffer,

Thanks for reporting this issue! We’ve received it and are reviewing it. We’ll provide updates as soon as possible.

CorieW avatar Apr 28 '25 09:04 CorieW

This could be due to the differences between these languages.

For example, in Python some_dict['invalid_property'] throws KeyError, when in Node some_dict['invalid_property'] returns undefined. Instead, you can probably use some_dict.get('invalid_property') (in Python) to get None returned.

Could you perhaps send over a code snippet that produces this issue, just to be certain?

CorieW avatar Apr 28 '25 13:04 CorieW

Closing due to inactivity. Please feel free to reopen or create a new issue if you need further assistance.

cabljac avatar May 30 '25 09:05 cabljac