-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
don't override timeout on with_overrides if not specified #3097
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -47,6 +47,8 @@ class Node(object): | |||||
ID, which from the registration step | ||||||
""" | ||||||
|
||||||
timeout_override_sentinel = object() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I usually see python sentinels as constants, thus all capitalized:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good - just updated |
||||||
|
||||||
def __init__( | ||||||
self, | ||||||
id: str, | ||||||
|
@@ -127,7 +129,7 @@ def metadata(self) -> _workflow_model.NodeMetadata: | |||||
def _override_node_metadata( | ||||||
self, | ||||||
name, | ||||||
timeout: Optional[Union[int, datetime.timedelta]] = None, | ||||||
timeout: Optional[Union[int, datetime.timedelta, object]] = timeout_override_sentinel, | ||||||
thomasjpfan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
retries: Optional[int] = None, | ||||||
interruptible: typing.Optional[bool] = None, | ||||||
cache: typing.Optional[bool] = None, | ||||||
|
@@ -142,14 +144,16 @@ def _override_node_metadata( | |||||
else: | ||||||
node_metadata = self._metadata | ||||||
|
||||||
if timeout is None: | ||||||
node_metadata._timeout = datetime.timedelta() | ||||||
elif isinstance(timeout, int): | ||||||
node_metadata._timeout = datetime.timedelta(seconds=timeout) | ||||||
elif isinstance(timeout, datetime.timedelta): | ||||||
node_metadata._timeout = timeout | ||||||
else: | ||||||
raise ValueError("timeout should be duration represented as either a datetime.timedelta or int seconds") | ||||||
if timeout is not Node.timeout_override_sentinel: | ||||||
if timeout is None: | ||||||
node_metadata._timeout = 0 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using timedelta for timeout value
Consider using Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #01a35d Is this a valid issue, or was it incorrectly flagged by the Agent?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pvditt For typing, I think this needs to be a timedelta object. |
||||||
elif isinstance(timeout, int): | ||||||
node_metadata._timeout = datetime.timedelta(seconds=timeout) | ||||||
elif isinstance(timeout, datetime.timedelta): | ||||||
node_metadata._timeout = timeout | ||||||
else: | ||||||
raise ValueError("timeout should be duration represented as either a datetime.timedelta or int seconds") | ||||||
|
||||||
if retries is not None: | ||||||
assert_not_promise(retries, "retries") | ||||||
node_metadata._retries = ( | ||||||
|
@@ -181,7 +185,7 @@ def with_overrides( | |||||
aliases: Optional[Dict[str, str]] = None, | ||||||
requests: Optional[Resources] = None, | ||||||
limits: Optional[Resources] = None, | ||||||
timeout: Optional[Union[int, datetime.timedelta]] = None, | ||||||
timeout: Optional[Union[int, datetime.timedelta, object]] = timeout_override_sentinel, | ||||||
retries: Optional[int] = None, | ||||||
interruptible: Optional[bool] = None, | ||||||
name: Optional[str] = None, | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -302,18 +302,42 @@ def my_wf(a: typing.List[str]) -> typing.List[str]: | |||||||||||||||||||||
] | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
preset_timeout = datetime.timedelta(seconds=100) | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
@pytest.mark.parametrize( | ||||||||||||||||||||||
"timeout,expected", | ||||||||||||||||||||||
[(None, datetime.timedelta()), (10, datetime.timedelta(seconds=10))], | ||||||||||||||||||||||
"timeout,t1_expected_timeout_overridden, t1_expected_timeout_unset, t2_expected_timeout_overridden, " | ||||||||||||||||||||||
"t2_expected_timeout_unset", | ||||||||||||||||||||||
[ | ||||||||||||||||||||||
(None, 0, 0, 0, preset_timeout), | ||||||||||||||||||||||
(10, datetime.timedelta(seconds=10), 0, | ||||||||||||||||||||||
datetime.timedelta(seconds=10), preset_timeout) | ||||||||||||||||||||||
], | ||||||||||||||||||||||
) | ||||||||||||||||||||||
def test_timeout_override(timeout, expected): | ||||||||||||||||||||||
def test_timeout_override( | ||||||||||||||||||||||
timeout, | ||||||||||||||||||||||
t1_expected_timeout_overridden, | ||||||||||||||||||||||
t1_expected_timeout_unset, | ||||||||||||||||||||||
t2_expected_timeout_overridden, | ||||||||||||||||||||||
t2_expected_timeout_unset, | ||||||||||||||||||||||
): | ||||||||||||||||||||||
Comment on lines
+319
to
+323
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider more descriptive parameter names
Consider using more descriptive parameter names. The current names Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #01a35d Is this a valid issue, or was it incorrectly flagged by the Agent?
|
||||||||||||||||||||||
@task | ||||||||||||||||||||||
def t1(a: str) -> str: | ||||||||||||||||||||||
return f"*~*~*~{a}*~*~*~" | ||||||||||||||||||||||
|
||||||||||||||||||||||
@task( | ||||||||||||||||||||||
timeout=preset_timeout | ||||||||||||||||||||||
) | ||||||||||||||||||||||
def t2(a: str) -> str: | ||||||||||||||||||||||
return f"*~*~*~{a}*~*~*~" | ||||||||||||||||||||||
|
||||||||||||||||||||||
@workflow | ||||||||||||||||||||||
def my_wf(a: str) -> str: | ||||||||||||||||||||||
return t1(a=a).with_overrides(timeout=timeout) | ||||||||||||||||||||||
s = t1(a=a).with_overrides(timeout=timeout) | ||||||||||||||||||||||
s1 = t1(a=s).with_overrides() | ||||||||||||||||||||||
s2 = t2(a=s1).with_overrides(timeout=timeout) | ||||||||||||||||||||||
s3 = t2(a=s2).with_overrides() | ||||||||||||||||||||||
return s3 | ||||||||||||||||||||||
|
||||||||||||||||||||||
serialization_settings = flytekit.configuration.SerializationSettings( | ||||||||||||||||||||||
project="test_proj", | ||||||||||||||||||||||
|
@@ -323,8 +347,11 @@ def my_wf(a: str) -> str: | |||||||||||||||||||||
env={}, | ||||||||||||||||||||||
) | ||||||||||||||||||||||
wf_spec = get_serializable(OrderedDict(), serialization_settings, my_wf) | ||||||||||||||||||||||
assert len(wf_spec.template.nodes) == 1 | ||||||||||||||||||||||
assert wf_spec.template.nodes[0].metadata.timeout == expected | ||||||||||||||||||||||
assert len(wf_spec.template.nodes) == 4 | ||||||||||||||||||||||
assert wf_spec.template.nodes[0].metadata.timeout == t1_expected_timeout_overridden | ||||||||||||||||||||||
assert wf_spec.template.nodes[1].metadata.timeout == t1_expected_timeout_unset | ||||||||||||||||||||||
assert wf_spec.template.nodes[2].metadata.timeout == t2_expected_timeout_overridden | ||||||||||||||||||||||
assert wf_spec.template.nodes[3].metadata.timeout == t2_expected_timeout_unset | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
def test_timeout_override_invalid_value(): | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider if using
object()
as a sentinel value is the best approach here. While it works, using a dedicated sentinel class orenum.Enum
could provide better type safety and clarity of intent.Code suggestion
Code Review Run #01a35d
Is this a valid issue, or was it incorrectly flagged by the Agent?