Skip to content

Commit 067e33a

Browse files
authored
Warn for bad combination of parameters for RedshiftDataOperator (#69524)
1 parent 354ee3c commit 067e33a

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

providers/amazon/src/airflow/providers/amazon/aws/operators/redshift_data.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ def __init__(
125125
self.deferrable = deferrable
126126
self.session_id = session_id
127127
self.session_keep_alive_seconds = session_keep_alive_seconds
128+
if self.deferrable and not self.wait_for_completion:
129+
self.log.warning(
130+
"deferrable=True and wait_for_completion=False are set; deferrable will be "
131+
"ignored and this task will run non-deferrable."
132+
)
128133

129134
def execute(self, context: Context) -> list[GetStatementResultResponseTypeDef] | list[str]:
130135
"""Execute a statement against Amazon Redshift."""

providers/amazon/tests/unit/amazon/aws/operators/test_redshift_data.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ def test_init(self):
8787
assert op.hook._verify is None
8888
assert op.hook._config is None
8989

90+
@mock.patch.object(RedshiftDataOperator, "log", new_callable=mock.MagicMock)
91+
def test_init_warns_when_deferrable_has_no_effect(self, mock_log):
92+
"""deferrable=True is a no-op when wait_for_completion=False; the user should be told."""
93+
RedshiftDataOperator(
94+
task_id=TASK_ID,
95+
database=DATABASE,
96+
sql=SQL,
97+
deferrable=True,
98+
wait_for_completion=False,
99+
)
100+
mock_log.warning.assert_called_once_with(
101+
"deferrable=True and wait_for_completion=False are set; deferrable will be "
102+
"ignored and this task will run non-deferrable."
103+
)
104+
90105
@mock.patch("airflow.providers.amazon.aws.hooks.redshift_data.RedshiftDataHook.execute_query")
91106
@mock.patch("airflow.providers.amazon.aws.hooks.redshift_data.RedshiftDataHook.conn")
92107
def test_execute(self, mock_conn, mock_exec_query):

0 commit comments

Comments
 (0)