From 3ce5904e5c560b0b81cfffc09cb46e1c6a5fe7a1 Mon Sep 17 00:00:00 2001 From: Theo Satabin Date: Thu, 8 Feb 2024 16:27:38 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Correction=20de=20la=20d=C3=A9tection=20d'o?= =?UTF-8?q?bjet=20absent=20en=20S3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### [Fixed] - `Storage` : dans le cas d'une lecture ou d'un test existence sur un objet S3 absent, le code dans la réponse n'est pas 404 mais NoSuchKey --- src/rok4/storage.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rok4/storage.py b/src/rok4/storage.py index 1cf0f6f..075baa0 100644 --- a/src/rok4/storage.py +++ b/src/rok4/storage.py @@ -366,7 +366,7 @@ def __get_cached_data_binary(path: str, ttl_hash: int, range: Tuple[int, int] = ) except botocore.exceptions.ClientError as e: - if e.response["Error"]["Code"] == "404": + if e.response["Error"]["Code"] == "NoSuchKey": raise FileNotFoundError(f"{storage_type.value}{path}") else: raise StorageError("S3", e) @@ -443,6 +443,9 @@ def get_data_binary(path: str, range: Tuple[int, int] = None) -> str: Returns: str: Data binary content """ + print("########################################") + print(f"get_data_binary {path}") + print("########################################") return __get_cached_data_binary(path, __get_ttl_hash(), range) @@ -573,7 +576,7 @@ def exists(path: str) -> bool: s3_client["client"].head_object(Bucket=bucket_name, Key=base_name) return True except botocore.exceptions.ClientError as e: - if e.response["Error"]["Code"] == "404": + if e.response["Error"]["Code"] == "NoSuchKey": return False else: raise StorageError("S3", e) From 029fca7f78785d63303f498834174c1dbead1348 Mon Sep 17 00:00:00 2001 From: Theo Satabin Date: Thu, 8 Feb 2024 16:27:38 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Correction=20de=20la=20d=C3=A9tection=20d'o?= =?UTF-8?q?bjet=20absent=20en=20S3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `Storage` : dans le cas d'une lecture ou d'un test existence sur un objet S3 absent, le code dans la réponse n'est pas 404 mais NoSuchKey --- src/rok4/storage.py | 7 +++++-- tests/test_storage.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rok4/storage.py b/src/rok4/storage.py index 1cf0f6f..075baa0 100644 --- a/src/rok4/storage.py +++ b/src/rok4/storage.py @@ -366,7 +366,7 @@ def __get_cached_data_binary(path: str, ttl_hash: int, range: Tuple[int, int] = ) except botocore.exceptions.ClientError as e: - if e.response["Error"]["Code"] == "404": + if e.response["Error"]["Code"] == "NoSuchKey": raise FileNotFoundError(f"{storage_type.value}{path}") else: raise StorageError("S3", e) @@ -443,6 +443,9 @@ def get_data_binary(path: str, range: Tuple[int, int] = None) -> str: Returns: str: Data binary content """ + print("########################################") + print(f"get_data_binary {path}") + print("########################################") return __get_cached_data_binary(path, __get_ttl_hash(), range) @@ -573,7 +576,7 @@ def exists(path: str) -> bool: s3_client["client"].head_object(Bucket=bucket_name, Key=base_name) return True except botocore.exceptions.ClientError as e: - if e.response["Error"]["Code"] == "404": + if e.response["Error"]["Code"] == "NoSuchKey": return False else: raise StorageError("S3", e) diff --git a/tests/test_storage.py b/tests/test_storage.py index dd7dddd..4e5e543 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -809,7 +809,7 @@ def test_exists_s3_ok(mocked_s3_client): assert False, f"S3 exists raises an exception: {exc}" s3_instance.head_object.side_effect = botocore.exceptions.ClientError( - operation_name="InvalidKeyPair.Duplicate", error_response={"Error": {"Code": "404"}} + operation_name="InvalidKeyPair.Duplicate", error_response={"Error": {"Code": "NoSuchKey"}} ) try: assert not exists("s3://bucket/object.ext")