Skip to content

Commit

Permalink
Pass parameters to parent class in SnowflakeSensorAsync (#1519)
Browse files Browse the repository at this point in the history
* Pass `parameters` to parent class in SnowflakeSensorAsync

Currently the SnowflakeSensorAsync does not propagate `parameters` to its parent class, SqlSensor. Because of this, `parameters` are not passed for execution and can cause task failures when doing so.
  • Loading branch information
josh-fell authored May 10, 2024
1 parent c7f7a74 commit f9f985d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion astronomer/providers/snowflake/sensors/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
*,
snowflake_conn_id: str,
sql: str,
parameters: str | None = None,
parameters: dict[str, Any] | None = None,
success: str | None = None,
failure: str | None = None,
fail_on_empty: bool = False,
Expand All @@ -63,6 +63,7 @@ def __init__(
super().__init__(
conn_id=snowflake_conn_id,
sql=sql,
parameters=parameters,
success=success,
failure=failure,
fail_on_empty=fail_on_empty,
Expand Down
22 changes: 22 additions & 0 deletions tests/snowflake/sensors/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,25 @@ def test_soft_fail_enable(self, context):
)
with pytest.raises(AirflowSkipException):
sensor.execute(context)

@mock.patch("airflow.providers.common.sql.sensors.sql.SqlSensor.__init__")
def test_call_with_parameters(self, mock_sql_sensor):
"""Ensure SQL parameters are passed to the SqlSensor parent class."""
SnowflakeSensorAsync(
sql="SELECT * FROM %(src)s;",
task_id="snowflake_sensor",
snowflake_conn_id=CONN_ID,
parameters={"src": "my_table"},
)

mock_sql_sensor.assert_called_once_with(
conn_id=CONN_ID,
task_id="snowflake_sensor",
sql="SELECT * FROM %(src)s;",
parameters={"src": "my_table"},
success=None,
failure=None,
fail_on_empty=False,
hook_params=None,
default_args={},
)

0 comments on commit f9f985d

Please sign in to comment.