Skip to content
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

Changed TaskSource key computation to handle OSError("source not available") #15583

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/prefect/cache_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def compute_key(
except TypeError:
lines = inspect.getsource(task_ctx.task.fn.__class__)
except OSError as exc:
if "could not get source code" in str(exc):
if str(exc) in {"could not get source code", "source code not available"}:
kzvezdarov marked this conversation as resolved.
Show resolved Hide resolved
lines = task_ctx.task.fn.__code__.co_code
else:
raise
Expand Down
23 changes: 11 additions & 12 deletions tests/test_cache_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,17 @@ def task_b_fn():
task_ctx_a = TaskRunContext.model_construct(task=mock_task_a)
task_ctx_b = TaskRunContext.model_construct(task=mock_task_b)

with patch(
"inspect.getsource", side_effect=OSError("could not get source code")
):
fallback_key_a = policy.compute_key(
task_ctx=task_ctx_a, inputs=None, flow_parameters=None
)
fallback_key_b = policy.compute_key(
task_ctx=task_ctx_b, inputs=None, flow_parameters=None
)

assert fallback_key_a and fallback_key_b
assert fallback_key_a != fallback_key_b
for os_error_msg in {"could not get source code", "source code not available"}:
with patch("inspect.getsource", side_effect=OSError(os_error_msg)):
fallback_key_a = policy.compute_key(
task_ctx=task_ctx_a, inputs=None, flow_parameters=None
)
fallback_key_b = policy.compute_key(
task_ctx=task_ctx_b, inputs=None, flow_parameters=None
)

assert fallback_key_a and fallback_key_b
assert fallback_key_a != fallback_key_b


class TestDefaultPolicy:
Expand Down
Loading