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

Add __wrapped__ property to _TaskDecorator #23830

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion airflow/decorators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ def __call__(self, *args, **kwargs) -> XComArg:
op.doc_md = self.function.__doc__
return XComArg(op)

@property
def __wrapped__(self) -> Function:
return self.function

@cached_property
def function_signature(self):
return inspect.signature(self.function)
Expand Down Expand Up @@ -495,6 +499,10 @@ class Task(Generic[Function]):

function: Function

@property
def __wrapped__(self) -> Function:
...

def expand(self, **kwargs: "Mappable") -> XComArg:
...

Expand Down Expand Up @@ -527,7 +535,7 @@ def task_decorator_factory(
**kwargs,
) -> TaskDecorator:
"""
A factory that generates a wrapper that raps a function into an Airflow operator.
A factory that generates a wrapper that wraps a function into an Airflow operator.
Accepts kwargs for operator kwarg. Can be reused in a single DAG.

:param python_callable: Function to decorate
Expand Down
17 changes: 17 additions & 0 deletions tests/decorators/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,3 +738,20 @@ def fn(arg1, arg2):

assert op.op_kwargs['arg1'] == "{{ ds }}"
assert op.op_kwargs['arg2'] == "fn"


def test_task_decorator_has_wrapped_attr():
"""
Test @task original underlying function is accessible
through the __wrapped__ attribute.
"""

def org_test_func():
pass

decorated_test_func = task_decorator(org_test_func)

assert hasattr(
decorated_test_func, '__wrapped__'
), "decorated function does not have __wrapped__ attribute"
assert decorated_test_func.__wrapped__ is org_test_func, "__wrapped__ attr is not the original function"