Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions airflow/providers/amazon/aws/sensors/athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
if TYPE_CHECKING:
from airflow.utils.context import Context

from airflow.exceptions import AirflowException
from airflow.exceptions import AirflowException, AirflowSkipException
from airflow.providers.amazon.aws.hooks.athena import AthenaHook
from airflow.sensors.base import BaseSensorOperator

Expand Down Expand Up @@ -78,7 +78,11 @@ def poke(self, context: Context) -> bool:
state = self.hook.poll_query_status(self.query_execution_id, self.max_retries, self.sleep_time)

if state in self.FAILURE_STATES:
raise AirflowException("Athena sensor failed")
# TODO: remove this if block when min_airflow_version is set to higher than 2.7.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity. Why? Why we no longer need this check from 2.7.1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

message = "Athena sensor failed"
if self.soft_fail:
raise AirflowSkipException(message)
raise AirflowException(message)

if state in self.INTERMEDIATE_STATES:
return False
Expand Down
14 changes: 13 additions & 1 deletion tests/providers/amazon/aws/sensors/test_athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import pytest

from airflow.exceptions import AirflowException
from airflow.exceptions import AirflowException, AirflowSkipException
from airflow.providers.amazon.aws.hooks.athena import AthenaHook
from airflow.providers.amazon.aws.sensors.athena import AthenaSensor

Expand Down Expand Up @@ -59,3 +59,15 @@ def test_poke_cancelled(self, mock_poll_query_status):
with pytest.raises(AirflowException) as ctx:
self.sensor.poke({})
assert "Athena sensor failed" in str(ctx.value)

@pytest.mark.parametrize(
"soft_fail, expected_exception", ((False, AirflowException), (True, AirflowSkipException))
)
def test_fail_poke(self, soft_fail, expected_exception):
self.sensor.soft_fail = soft_fail
message = "Athena sensor failed"
with pytest.raises(expected_exception, match=message), mock.patch(
"airflow.providers.amazon.aws.hooks.athena.AthenaHook.poll_query_status"
) as poll_query_status:
poll_query_status.return_value = "FAILED"
self.sensor.poke(context={})