From 0df31c6b17adc4c3f6235bed4cfcb0a3b539668b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Jan 2024 16:32:36 +0000 Subject: [PATCH 1/3] =?UTF-8?q?[pre-commit.ci]=20Mise=20=C3=A0=20jour=20de?= =?UTF-8?q?s=20git=20hooks.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.4.0 → v4.5.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.4.0...v4.5.0) - [github.com/astral-sh/ruff-pre-commit: v0.0.291 → v0.1.9](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.291...v0.1.9) - [github.com/psf/black: 23.9.1 → 23.12.1](https://github.com/psf/black/compare/23.9.1...23.12.1) - [github.com/pycqa/isort: 5.12.0 → 5.13.2](https://github.com/pycqa/isort/compare/5.12.0...5.13.2) - [github.com/asottile/pyupgrade: v3.13.0 → v3.15.0](https://github.com/asottile/pyupgrade/compare/v3.13.0...v3.15.0) --- .pre-commit-config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f32290e..83b61bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ exclude: ".venv|__pycache__|tests/dev/|tests/fixtures/" fail_fast: false repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-added-large-files args: ["--maxkb=1024"] @@ -22,25 +22,25 @@ repos: args: [--markdown-linebreak-ext=md] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.0.291" + rev: "v0.1.9" hooks: - id: ruff args: ["--fix-only", "--target-version=py38"] - repo: https://github.com/psf/black - rev: 23.9.1 + rev: 23.12.1 hooks: - id: black args: ["--target-version=py38"] - repo: https://github.com/pycqa/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort args: ["--profile", "black", "--filter-files"] - repo: https://github.com/asottile/pyupgrade - rev: v3.13.0 + rev: v3.15.0 hooks: - id: pyupgrade args: From 3ce5904e5c560b0b81cfffc09cb46e1c6a5fe7a1 Mon Sep 17 00:00:00 2001 From: Theo Satabin Date: Thu, 8 Feb 2024 16:27:38 +0100 Subject: [PATCH 2/3] =?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 3/3] =?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")