Skip to content

Commit

Permalink
encapsulate qualname check
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz committed Jul 22, 2024
1 parent 10255c9 commit f8438c9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/prefect/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ def _generate_task_key(fn: Callable) -> str:
Args:
fn: The function to generate a task key for.
"""
if not hasattr(fn, "__qualname__"):
return to_qualified_name(type(fn))

qualname = fn.__qualname__.split(".")[-1]
source_hash = h[:8] if (h := hash_objects(inspect.getsource(fn))) else "unknown"
return f"{qualname}-{source_hash}"
Expand Down Expand Up @@ -386,10 +389,7 @@ def __init__(

self.tags = set(tags if tags else [])

if not hasattr(self.fn, "__qualname__"):
self.task_key = to_qualified_name(type(self.fn))
else:
self.task_key = _generate_task_key(self.fn)
self.task_key = _generate_task_key(self.fn)

if cache_policy is not NotSet and cache_key_fn is not None:
logger.warning(
Expand Down

0 comments on commit f8438c9

Please sign in to comment.