Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of failed items in Base.put #76

Merged
merged 3 commits into from
Sep 13, 2023
Merged

Conversation

lemonyte
Copy link
Contributor

@lemonyte lemonyte commented Aug 31, 2022

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:

{
    "failed": {
        "items": [
            {"": "foo", "detabase_id": "<id>", "key": "<key>"}
        ]
    }
}

The put method was expecting a "processed" key to be present, and consequently failing when no such key existed.

return res["processed"]["items"][0] if res and code == 207 else None

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 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?

@hozan23
Copy link
Contributor

hozan23 commented Sep 13, 2023

Thanks @lemonyte

@hozan23 hozan23 merged commit 961a0b2 into deta:master Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants