Skip to content

Commit

Permalink
refactor: Fixed static checks
Browse files Browse the repository at this point in the history
  • Loading branch information
davidblain-infrabel authored and potiuk committed Jan 2, 2025
1 parent eedcd52 commit 38f654a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 23 deletions.
7 changes: 3 additions & 4 deletions providers/src/airflow/providers/common/sql/triggers/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
from airflow.triggers.base import BaseTrigger, TriggerEvent

if TYPE_CHECKING:
from typing import (
Any,
AsyncIterator,
)
from collections.abc import AsyncIterator
from typing import Any


class SQLExecuteQueryTrigger(BaseTrigger):
Expand All @@ -39,6 +37,7 @@ class SQLExecuteQueryTrigger(BaseTrigger):
:param conn_id: the connection ID used to connect to the database
:param hook_params: hook parameters
"""

def __init__(
self,
sql: str | list[str],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ def get_hook(cls, conn_id: str, hook_params: dict | None = None) -> BaseHook:

def get_paginated_sql(self, offset: int) -> str:
"""Format the paginated SQL statement using the current format."""
return self._paginated_sql_statement_format.format(
self.sql, self.chunk_size, offset
)
return self._paginated_sql_statement_format.format(self.sql, self.chunk_size, offset)

def render_template_fields(
self,
Expand Down Expand Up @@ -191,9 +189,7 @@ def execute_complete(
if event.get("status") == "failure":
raise AirflowException(event.get("message"))

destination_hook = BaseHook.get_hook(
self.destination_conn_id, hook_params=self.destination_hook_params
)
destination_hook = BaseHook.get_hook(self.destination_conn_id, hook_params=self.destination_hook_params)

results = event.get("results")

Expand Down Expand Up @@ -221,12 +217,8 @@ def execute_complete(
self.log.info("Offset increased to %d", offset)
self.xcom_push(context=context, key="offset", value=offset)

self.log.info(
"Inserting %d rows into %s", len(results), self.destination_conn_id
)
insert_rows(
table=self.destination_table, rows=results, **self.insert_args
)
self.log.info("Inserting %d rows into %s", len(results), self.destination_conn_id)
insert_rows(table=self.destination_table, rows=results, **self.insert_args)
self.log.info(
"Inserting %d rows into %s done!",
len(results),
Expand Down
1 change: 1 addition & 0 deletions providers/tests/common/sql/triggers/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from unittest import mock

import pytest

from airflow.providers.common.sql.hooks.sql import DbApiHook
from airflow.providers.common.sql.triggers.sql import SQLExecuteQueryTrigger
from airflow.triggers.base import TriggerEvent
Expand Down
3 changes: 2 additions & 1 deletion providers/tests/microsoft/azure/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
from contextlib import contextmanager
from unittest.mock import patch

from airflow.providers.microsoft.azure.hooks.msgraph import KiotaRequestAdapterHook
from kiota_http.httpx_request_adapter import HttpxRequestAdapter

from airflow.providers.microsoft.azure.hooks.msgraph import KiotaRequestAdapterHook

from providers.tests.microsoft.conftest import get_airflow_connection


Expand Down
8 changes: 3 additions & 5 deletions providers/tests/microsoft/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@
from inspect import currentframe
from json import JSONDecodeError
from os.path import dirname, join
from typing import TYPE_CHECKING, Any, TypeVar
from typing import Any, TypeVar
from unittest.mock import MagicMock

import pytest
from airflow.models import Connection
from airflow.providers.microsoft.azure.hooks.powerbi import PowerBIHook
from httpx import Headers, Response
from msgraph_core import APIVersion

if TYPE_CHECKING:
pass
from airflow.models import Connection
from airflow.providers.microsoft.azure.hooks.powerbi import PowerBIHook

T = TypeVar("T", dict, str, Connection)

Expand Down
3 changes: 2 additions & 1 deletion tests_common/test_utils/mock_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@


def mock_context(task) -> Context:
from sqlalchemy.orm import Session

from airflow.models import TaskInstance
from airflow.utils.session import NEW_SESSION
from airflow.utils.state import TaskInstanceState
from airflow.utils.xcom import XCOM_RETURN_KEY
from sqlalchemy.orm import Session

values: dict[str, Any] = {}

Expand Down

0 comments on commit 38f654a

Please sign in to comment.