Fix handling of failed items in Base.put
#76
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Problem
The
put
method would raise a KeyError when trying to submit a dictionary. Issue originally brought up in deta/cloud-docs#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.deta-python/deta/base.py
Line 161 in 49d53b8
The 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?