Skip to content

Commit

Permalink
Fix script decorator to properly wrap the underlying function (#592)
Browse files Browse the repository at this point in the history
This fixes the script decorator so that - 
- Args are passed as intended
- The wrapper is wrapped with functools.wraps to ensure proper stack
traces. See
https://docs.python.org/3/library/functools.html#functools.wraps

Signed-off-by: Sambhav Kothari <[email protected]>
  • Loading branch information
sambhav authored Apr 25, 2023
1 parent aef1d27 commit 69091e1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/hera/workflows/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import inspect
import textwrap
from abc import abstractmethod
from functools import wraps
from typing import Any, Callable, Dict, List, Optional, Type, Union

from pydantic import root_validator, validator
Expand Down Expand Up @@ -261,11 +262,12 @@ def script_wrapper(func: Callable) -> Callable:
"""
s = Script(name=func.__name__.replace("_", "-"), source=func, **script_kwargs)

def task_wrapper(**kwargs) -> Union[Task, Step]:
@wraps(func)
def task_wrapper(*args, **kwargs) -> Union[Task, Step]:
"""Invokes a `Script` object's `__call__` method using the given `task_params`"""
if _context.active:
return s.__call__(**kwargs) # type: ignore
return func(**kwargs)
return s.__call__(*args, **kwargs) # type: ignore
return func(*args, **kwargs)

# Set the wrapped function to the original function so that we can use it later
task_wrapper.wrapped_function = func # type: ignore
Expand Down

0 comments on commit 69091e1

Please sign in to comment.