From c3863e24c7bcebfc76a696082a2b80e4af013e30 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 23 Feb 2020 17:35:27 +0100 Subject: [PATCH] Bugfixes --- .build.yml | 4 ++-- blobstash/base/client.py | 10 ++++++++-- blobstash/docstore/__init__.py | 11 +++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.build.yml b/.build.yml index 9143152..a7412a2 100644 --- a/.build.yml +++ b/.build.yml @@ -9,8 +9,8 @@ tasks: - go: | mkdir go export GOPATH=/home/build/go - wget -q https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz - sudo tar -C /usr/local -xzf go1.13.4.linux-amd64.tar.gz + wget -q https://dl.google.com/go/go1.13.8.linux-amd64.tar.gz + sudo tar -C /usr/local -xzf go1.13.8.linux-amd64.tar.gz - blobstash: | export GOPATH=/home/build/go cd blobstash diff --git a/blobstash/base/client.py b/blobstash/base/client.py index 518c29e..e8e9df7 100644 --- a/blobstash/base/client.py +++ b/blobstash/base/client.py @@ -1,4 +1,7 @@ """BlobStash client.""" +from typing import Any +from typing import Dict +from typing import Optional import json import os from urllib.parse import urljoin @@ -7,6 +10,8 @@ import requests DEFAULT_BASE_URL = "http://localhost:8050" +_JSON = Dict[str, Any] + class Client: """Basic client for API-specific client to build upon.""" @@ -16,7 +21,7 @@ class Client: self.api_key = api_key or os.getenv("BLOBSTASH_API_KEY") self.json_encoder = json_encoder - def request(self, verb, path, **kwargs): + def request(self, verb: str, path: str, **kwargs) -> Optional[_JSON]: """Helper for making authenticated request to BlobStash.""" raw = kwargs.pop("raw", False) json_data = kwargs.pop("json", None) @@ -34,4 +39,5 @@ class Client: return r r.raise_for_status() - return r.json() + if r.status_code != 204: + return r.json() diff --git a/blobstash/docstore/__init__.py b/blobstash/docstore/__init__.py index b804a88..2f673e3 100644 --- a/blobstash/docstore/__init__.py +++ b/blobstash/docstore/__init__.py @@ -367,16 +367,19 @@ class Collection: def delete(self, doc_or_docs): """Delete the given document/list of document.""" - if isinstance(doc_or_docs, list): + if not isinstance(doc_or_docs, list): docs = [doc_or_docs] + for doc in docs: if isinstance(doc, dict): try: - _id = doc["_id"] + _id = doc["_id"].id() except KeyError: raise MissingIDError - elif isinstance(_id, ID): - _id = _id.id() + elif isinstance(doc, ID): + _id = doc.id() + elif isinstance(doc, str): + _id = doc else: raise NotADocumentError -- 2.45.2