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

Workaround for missing has_key implementation #100

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently breaks master btw

~/minio server ~/s3 &
5 changes: 5 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
*********

Next
====

* Fix an issue where `key in store` check for the new azure-storage-blob API did raise

0.14.0
======

Expand Down
9 changes: 8 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,13 @@ 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)
with map_azure_exceptions(key, ("BlobNotFound",)):
# One of the very few methods which do not mutate state
blob_client.get_blob_properties()
return True
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