Skip to content

Commit

Permalink
Added test case to cover the scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
soamicharan committed Nov 7, 2024
1 parent cd4e113 commit 8842ba6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/prefect/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,9 @@ def get_decorator_function_name(func_decorator):

# Exclude callable type keyword arguments from flow decorator
for func_decorator in func_def.decorator_list:
if not hasattr(func_decorator, "keywords"):
continue

func_decorator.keywords = list(
filter(
lambda keyword_arg: keyword_arg.arg not in exclude_keyword_args,
Expand Down
27 changes: 27 additions & 0 deletions tests/test_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -5225,3 +5225,30 @@ def dog():

with pytest.raises(NameError, match="name 'not_a_function' is not defined"):
safe_load_flow_from_entrypoint(entrypoint)()

def test_remove_callback_hooks_for_missing_import(self, tmp_path: Path):
flow_source = dedent(
"""
from prefect import flow
from non_existent import DEFAULT_NAME, DEFAULT_AGE
def test_callback():
print(DEFAULT_NAME)
def wrapper(*args, **kwargs):
pass
return wrapper
@flow(on_running=[test_callback()])
def flow_function(name = DEFAULT_NAME, age = DEFAULT_AGE) -> str:
return name, age
"""
)

tmp_path.joinpath("flow.py").write_text(flow_source)

entrypoint = f"{tmp_path.joinpath('flow.py')}:flow_function"

result = safe_load_flow_from_entrypoint(entrypoint)
assert result is not None

0 comments on commit 8842ba6

Please sign in to comment.