The put method now checks if a "processed" exists before accessing it. If it does not exist, it handles the response as any other unsuccessful response, and returns None.
Changes
Base.put will no longer throw a KeyError when a PUT request fails and the API returns a response with the failed field
Added workaround when raising urllib.error.HTTPError so the traceback prints properly
Fixed TTL tests
Additional
Perhaps it would be a good idea to make sure the API always returns a "processed" key, which would be empty when all items failed to add?
The Problem
The
put
method would raise a KeyError when trying to submit a dictionary. Issue originally brought up in https://github.com/deta/docs/discussions/431.The Cause
The data dictionary that was submitted had empty keys (i.e.
{"": "foo"}
), which the API rejected and returned in a response like the following:The
put
method was expecting a"processed"
key to be present, and consequently failing when no such key existed. https://github.com/deta/deta-python/blob/49d53b8aa193f59a1085928cecf428710c1c69fa/deta/base.py#L161The Solution
The
put
method now checks if a"processed"
exists before accessing it. If it does not exist, it handles the response as any other unsuccessful response, and returnsNone
.Changes
Base.put
will no longer throw a KeyError when a PUT request fails and the API returns a response with thefailed
fieldurllib.error.HTTPError
so the traceback prints properlyAdditional
Perhaps it would be a good idea to make sure the API always returns a
"processed"
key, which would be empty when all items failed to add?