Skip to content

Commit

Permalink
Workaround for missing has_key implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
fjetter committed Jan 22, 2020
1 parent df60b79 commit b969715
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .travis/start_minio.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export MINIO_ACCESS_KEY=minio
export MINIO_SECRET_KEY=miniostorage

mkdir -p ~/s3
~/minio version

~/minio --version
~/minio server ~/s3 &
10 changes: 9 additions & 1 deletion simplekv/net/_azurestore_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import hashlib
import io
from contextlib import contextmanager
from azure.core.exceptions import ResourceNotFoundError

from .._compat import binary_type
from .. import KeyValueStore
Expand Down Expand Up @@ -95,7 +96,14 @@ def _get(self, key):
return downloader.readall()

def _has_key(self, key):
return self.blob_container_client.exists(key)
# https://github.com/Azure/azure-sdk-for-python/issues/9507
blob_client = self.blob_container_client.get_blob_client(key)
try:
# One of the very few methods which do not mutate state
blob_client.get_blob_properties()
return True
except ResourceNotFoundError:
return False

def iter_keys(self, prefix=None):
blobs = self.blob_container_client.list_blobs(name_starts_with=prefix)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_azure_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def store(self):
public=False)
_delete_container(conn_string, container)

def test_exists(self, store):
assert "key" not in store
store.put("key", b"value")
assert "key" in store


class TestExtendedKeysAzureStorage(TestAzureStorage, ExtendedKeyspaceTests):
@pytest.fixture
Expand Down

0 comments on commit b969715

Please sign in to comment.