Skip to content

Commit

Permalink
Ensure execution_timeout as timedelta (#23655)
Browse files Browse the repository at this point in the history
  • Loading branch information
pingzh authored May 16, 2022
1 parent de3c038 commit 6f82fc7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions airflow/models/baseoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,13 @@ def __init__(
self.email = email
self.email_on_retry = email_on_retry
self.email_on_failure = email_on_failure

if execution_timeout is not None and not isinstance(execution_timeout, timedelta):
raise ValueError(
f'execution_timeout must be timedelta object but passed as type: {type(execution_timeout)}'
)
self.execution_timeout = execution_timeout

self.on_execute_callback = on_execute_callback
self.on_failure_callback = on_failure_callback
self.on_success_callback = on_success_callback
Expand Down
11 changes: 11 additions & 0 deletions tests/models/test_baseoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ def test_default_args(self):
with pytest.raises(AirflowException, match="missing keyword argument 'test_sub_param'"):
DummySubClass(default_args=default_args)

def test_execution_timeout_type(self):
with pytest.raises(
ValueError, match="execution_timeout must be timedelta object but passed as type: <class 'str'>"
):
BaseOperator(task_id='test', execution_timeout="1")

with pytest.raises(
ValueError, match="execution_timeout must be timedelta object but passed as type: <class 'int'>"
):
BaseOperator(task_id='test', execution_timeout=1)

def test_incorrect_default_args(self):
default_args = {'test_param': True, 'extra_param': True}
dummy_class = DummyClass(default_args=default_args)
Expand Down

0 comments on commit 6f82fc7

Please sign in to comment.