Skip to content

Commit

Permalink
allow non-positive values in gettimedelta
Browse files Browse the repository at this point in the history
Before this commit, gettimedelta method was preventing
user to provide non-positive values. Now it is totally up to
users to provide a sensible value for this configuration
  • Loading branch information
sercansagmaninvent committed Apr 10, 2022
1 parent 39a571b commit 7f30f25
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 33 deletions.
2 changes: 1 addition & 1 deletion airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
default: "downstream"
- name: default_task_execution_timeout
description: |
The default task execution_timeout value for the operators. Expected positive integer value to
The default task execution_timeout value for the operators. Expected an integer value to
be passed into timedelta as seconds. If not specified, then the value is considered as None,
meaning that the operators are never timed out by default.
version_added: 2.3.0
Expand Down
2 changes: 1 addition & 1 deletion airflow/config_templates/default_airflow.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ default_task_retries = 0
# The weighting method used for the effective total priority weight of the task
default_task_weight_rule = downstream

# The default task execution_timeout value for the operators. Expected positive integer value to
# The default task execution_timeout value for the operators. Expected an integer value to
# be passed into timedelta as seconds. If not specified, then the value is considered as None,
# meaning that the operators are never timed out by default.
default_task_execution_timeout =
Expand Down
8 changes: 0 additions & 8 deletions airflow/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,14 +632,6 @@ def gettimedelta(self, section, key, fallback=None, **kwargs) -> Optional[dateti
f'Current value: "{val}".'
)

# the given value must be positive.
if int_val <= 0:
raise AirflowConfigException(
f'Failed to convert value to timedelta in `seconds`. '
f'Value must be greater than zero. '
f'Please check "{key}" key in "{section}" section. Current value: "{val}".'
)

try:
return datetime.timedelta(seconds=int_val)
except OverflowError as err:
Expand Down
30 changes: 7 additions & 23 deletions tests/core/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,14 +851,14 @@ def test_gettimedelta(self):
# too large value for C int
key3 = 999999999999999
# Equals to None
[valid]
# negative value
key4 = -1
# zero
key5 = 0
[valid]
# valid seconds
# positive value
key6 = 300
[default]
Expand Down Expand Up @@ -894,26 +894,10 @@ def test_gettimedelta(self):
):
test_conf.gettimedelta("invalid", "key3")

with pytest.raises(
AirflowConfigException,
match=re.escape(
'Failed to convert value to timedelta in `seconds`. '
'Value must be greater than zero. '
'Please check "key4" key in "invalid" section. Current value: "-1".'
),
):
test_conf.gettimedelta("invalid", "key4")

with pytest.raises(
AirflowConfigException,
match=re.escape(
'Failed to convert value to timedelta in `seconds`. '
'Value must be greater than zero. '
'Please check "key5" key in "invalid" section. Current value: "0".'
),
):
test_conf.gettimedelta("invalid", "key5")

assert isinstance(test_conf.gettimedelta('valid', 'key4'), datetime.timedelta)
assert test_conf.gettimedelta('valid', 'key4') == datetime.timedelta(seconds=-1)
assert isinstance(test_conf.gettimedelta('valid', 'key5'), datetime.timedelta)
assert test_conf.gettimedelta('valid', 'key5') == datetime.timedelta(seconds=0)
assert isinstance(test_conf.gettimedelta('valid', 'key6'), datetime.timedelta)
assert test_conf.gettimedelta('valid', 'key6') == datetime.timedelta(seconds=300)
assert isinstance(test_conf.gettimedelta('default', 'key7'), type(None))
Expand Down

0 comments on commit 7f30f25

Please sign in to comment.