Skip to content

Commit

Permalink
Merge pull request #1870 from camptocamp/avoud-wrong-error
Browse files Browse the repository at this point in the history
Azure: Fix error on delete tile, add more exceptions
  • Loading branch information
sbrunner authored Jul 5, 2024
2 parents ba884b7 + b21b002 commit b99f0aa
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tilecloud/store/azure_storage_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from tilecloud import Tile, TileLayout, TileStore

LOGGER = logging.getLogger(__name__)
_LOGGER = logging.getLogger(__name__)


class AzureStorageBlobTileStore(TileStore):
Expand Down Expand Up @@ -56,32 +56,35 @@ def __contains__(self, tile: Tile) -> bool:
if not tile:
return False
key_name = self.tilelayout.filename(tile.tilecoord, tile.metadata)
return len(self.container_client.list_blobs(name_starts_with=key_name)) > 0 # type: ignore
blob = self.container_client.get_blob_client(blob=key_name)
return blob.exists()

def delete_one(self, tile: Tile) -> Tile:
try:
key_name = self.tilelayout.filename(tile.tilecoord, tile.metadata)
if not self.dry_run:
blob = self.container_client.get_blob_client(blob=key_name)
blob.delete_blob()
if blob.exists():
blob.delete_blob()
except Exception as exc: # pylint: disable=broad-except
_LOGGER.exception(exc)
tile.error = exc
return tile

def get_one(self, tile: Tile) -> Optional[Tile]:
key_name = self.tilelayout.filename(tile.tilecoord, tile.metadata)
try:
blob = self.container_client.get_blob_client(blob=key_name)
if not blob.exists():
return None
data = blob.download_blob().readall()
assert isinstance(data, bytes) or data is None
tile.data = data
properties = blob.get_blob_properties()
tile.content_encoding = properties.content_settings.content_encoding
tile.content_type = properties.content_settings.content_type
except ResourceNotFoundError:
return None
except Exception as exc: # pylint: disable=broad-except
LOGGER.exception(exc)
_LOGGER.exception(exc)
tile.error = exc
return tile

Expand Down Expand Up @@ -112,6 +115,7 @@ def put_one(self, tile: Tile) -> Tile:
),
)
except Exception as exc: # pylint: disable=broad-except
_LOGGER.exception(exc)
tile.error = exc

return tile

0 comments on commit b99f0aa

Please sign in to comment.