Content-Length: 413371 | pFad | https://github.com/apache/airflow/commit/ff23a30e5b51f4ba7316fa803a85b89b7dd5f6fe

F4 fix(providers/google-marketing-platform): respect soft_fail argument … · apache/airflow@ff23a30 · GitHub
Skip to content

Commit ff23a30

Browse files
authored
fix(providers/google-marketing-platform): respect soft_fail argument when exception is raised (#34165)
1 parent f5857a9 commit ff23a30

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

airflow/providers/google/marketing_platform/sensors/display_video.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from typing import TYPE_CHECKING, Sequence
2121

22-
from airflow import AirflowException
22+
from airflow.exceptions import AirflowException, AirflowSkipException
2323
from airflow.providers.google.marketing_platform.hooks.display_video import GoogleDisplayVideo360Hook
2424
from airflow.sensors.base import BaseSensorOperator
2525

@@ -86,9 +86,12 @@ def poke(self, context: Context) -> bool:
8686
impersonation_chain=self.impersonation_chain,
8787
)
8888
operation = hook.get_sdf_download_operation(operation_name=self.operation_name)
89-
9089
if "error" in operation:
91-
raise AirflowException(f'The operation finished in error with {operation["error"]}')
90+
# TODO: remove this if block when min_airflow_version is set to higher than 2.7.1
91+
message = f'The operation finished in error with {operation["error"]}'
92+
if self.soft_fail:
93+
raise AirflowSkipException(message)
94+
raise AirflowException(message)
9295
if operation and operation.get("done"):
9396
return True
9497
return False

tests/providers/google/marketing_platform/sensors/test_display_video.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,23 @@
1919

2020
from unittest import mock
2121

22+
import pytest
23+
24+
from airflow.exceptions import AirflowException, AirflowSkipException
2225
from airflow.providers.google.marketing_platform.sensors.display_video import (
2326
GoogleDisplayVideo360GetSDFDownloadOperationSensor,
2427
GoogleDisplayVideo360RunQuerySensor,
2528
)
2629

30+
MODULE_NAME = "airflow.providers.google.marketing_platform.sensors.display_video"
31+
2732
API_VERSION = "api_version"
2833
GCP_CONN_ID = "google_cloud_default"
2934

3035

3136
class TestGoogleDisplayVideo360RunQuerySensor:
32-
@mock.patch("airflow.providers.google.marketing_platform.sensors.display_video.GoogleDisplayVideo360Hook")
33-
@mock.patch("airflow.providers.google.marketing_platform.sensors.display_video.BaseSensorOperator")
37+
@mock.patch(f"{MODULE_NAME}.GoogleDisplayVideo360Hook")
38+
@mock.patch(f"{MODULE_NAME}.BaseSensorOperator")
3439
def test_poke(self, mock_base_op, hook_mock):
3540
query_id = "QUERY_ID"
3641
report_id = "REPORT_ID"
@@ -46,8 +51,8 @@ def test_poke(self, mock_base_op, hook_mock):
4651

4752

4853
class TestGoogleDisplayVideo360Sensor:
49-
@mock.patch("airflow.providers.google.marketing_platform.sensors.display_video.GoogleDisplayVideo360Hook")
50-
@mock.patch("airflow.providers.google.marketing_platform.sensors.display_video.BaseSensorOperator")
54+
@mock.patch(f"{MODULE_NAME}.GoogleDisplayVideo360Hook")
55+
@mock.patch(f"{MODULE_NAME}.BaseSensorOperator")
5156
def test_poke(self, mock_base_op, hook_mock):
5257
operation_name = "operation_name"
5358
op = GoogleDisplayVideo360GetSDFDownloadOperationSensor(
@@ -65,3 +70,23 @@ def test_poke(self, mock_base_op, hook_mock):
6570
hook_mock.return_value.get_sdf_download_operation.assert_called_once_with(
6671
operation_name=operation_name
6772
)
73+
74+
@pytest.mark.parametrize(
75+
"soft_fail, expected_exception", ((False, AirflowException), (True, AirflowSkipException))
76+
)
77+
@mock.patch(f"{MODULE_NAME}.GoogleDisplayVideo360Hook")
78+
@mock.patch(f"{MODULE_NAME}.BaseSensorOperator")
79+
def test_poke_with_exception(
80+
self, mock_base_op, hook_mock, soft_fail: bool, expected_exception: AirflowException
81+
):
82+
operation_name = "operation_name"
83+
op = GoogleDisplayVideo360GetSDFDownloadOperationSensor(
84+
operation_name=operation_name,
85+
api_version=API_VERSION,
86+
task_id="test_task",
87+
soft_fail=soft_fail,
88+
)
89+
hook_mock.return_value.get_sdf_download_operation.return_value = {"error": "error"}
90+
91+
with pytest.raises(expected_exception, match="The operation finished in error with error"):
92+
op.poke(context=None)

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/apache/airflow/commit/ff23a30e5b51f4ba7316fa803a85b89b7dd5f6fe

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy