From cf7db12f8d8155d086d04856954578fec8599a02 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:14:15 +0530 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#1381) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.6 → v0.1.7](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.6...v0.1.7) - [github.com/PyCQA/bandit: 1.7.5 → 1.7.6](https://github.com/PyCQA/bandit/compare/1.7.5...1.7.6) * Fix mypy * Fix mypy * Fix mypy --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Pankaj --- .pre-commit-config.yaml | 4 ++-- astronomer/providers/google/cloud/hooks/dataproc.py | 12 ++++++++---- .../providers/snowflake/hooks/snowflake_sql_api.py | 4 ++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 76ea7a1fc..edd22a45f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -55,7 +55,7 @@ repos: additional_dependencies: [black==22.3.0] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.1.6' + rev: 'v0.1.7' hooks: - id: ruff args: ["--config", "./pyproject.toml"] @@ -90,7 +90,7 @@ repos: additional_dependencies: ['toml'] - repo: https://github.com/PyCQA/bandit - rev: 1.7.5 + rev: 1.7.6 hooks: - id: bandit # Excluding Example DAGs temporarily until they can be fixed diff --git a/astronomer/providers/google/cloud/hooks/dataproc.py b/astronomer/providers/google/cloud/hooks/dataproc.py index 258813566..923e298f5 100644 --- a/astronomer/providers/google/cloud/hooks/dataproc.py +++ b/astronomer/providers/google/cloud/hooks/dataproc.py @@ -3,9 +3,8 @@ from airflow.providers.google.common.consts import CLIENT_INFO from airflow.providers.google.common.hooks.base_google import GoogleBaseHook -from google.api_core import gapic_v1 +from google.api_core import gapic_v1, retry_async as retries from google.api_core.client_options import ClientOptions -from google.api_core.retry import Retry from google.cloud.dataproc_v1 import ( ClusterControllerAsyncClient, Job, @@ -13,6 +12,11 @@ ) from google.cloud.dataproc_v1.types import clusters +try: + OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: no cover + OptionalRetry = Union[retries.AsyncRetry, object] # type: ignore[misc] + JobType = Union[Job, Any] @@ -68,7 +72,7 @@ async def get_cluster( region: str, cluster_name: str, project_id: str, - retry: Union[Retry, gapic_v1.method._MethodDefault] = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> clusters.Cluster: """ @@ -98,7 +102,7 @@ async def get_job( timeout: float = 5, region: Optional[str] = None, location: Optional[str] = None, - retry: Union[Retry, gapic_v1.method._MethodDefault] = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> JobType: """ diff --git a/astronomer/providers/snowflake/hooks/snowflake_sql_api.py b/astronomer/providers/snowflake/hooks/snowflake_sql_api.py index 9ab17a112..081515001 100644 --- a/astronomer/providers/snowflake/hooks/snowflake_sql_api.py +++ b/astronomer/providers/snowflake/hooks/snowflake_sql_api.py @@ -140,6 +140,8 @@ def execute_query( try: response.raise_for_status() except requests.exceptions.HTTPError as e: # pragma: no cover + if e.response is None: + raise e raise AirflowException( f"Response: {e.response.content!r}, " f"Status Code: {e.response.status_code}" ) # pragma: no cover @@ -203,6 +205,8 @@ def check_query_output(self, query_ids: list[str]) -> None: response.raise_for_status() self.log.info(response.json()) except requests.exceptions.HTTPError as e: + if e.response is None: # pragma: no cover + raise e raise AirflowException( f"Response: {e.response.content!r}, Status Code: {e.response.status_code}" )