You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
_TaskDecorator has no __wrapped__ attribute in v2.3.0 #23688
I run a unit test on a task which is defined using the task decorator. In the unit test, I unwrap the task decorator with the __wrapped__ attribute, but this no longer works in v2.3.0. It works in v2.2.5.
What you think should happen instead
I expect the wrapped function to be returned. This was what occurred in v2.2.5
When running pytest on the airflow v2.3.0 the following error is thrown: AttributeError: '_TaskDecorator' object has no attribute '__wrapped__'
How to reproduce
Here's a rough outline of the code.
A module hello.py contains the task definition:
from airflow.decorators import task
@task
def hello_airflow():
print('hello airflow')
and the test contains
from hello import hello_airflow
def test_hello_airflow():
hello_airflow.__wrapped__()
Unfortunately the decorator using functools.wraps() under the hood (which is responsible for __wrapped__) is an implementation detail, and we never thought about keeping compatibility. It could still be added easily enough though (just add a @property on _TaskDecorator) and I guess no-one would really complain. Would you mind working on a PR for this?
In class TaskDecorator (the one without an underscore), add
@propertydef__wrapped__(self) ->Function:
...
The first class adds the actual property (so you can access this in tests), while the other declares the interface. The second one is not strictly necessary, but it’s good to provide it for editor autocompletion and stuff.
Activity
boring-cyborg commentedon May 12, 2022
Thanks for opening your first issue here! Be sure to follow the issue template!
uranusjr commentedon May 12, 2022
Unfortunately the decorator using
functools.wraps()under the hood (which is responsible for__wrapped__) is an implementation detail, and we never thought about keeping compatibility. It could still be added easily enough though (just add a@propertyon_TaskDecorator) and I guess no-one would really complain. Would you mind working on a PR for this?ddeepwell commentedon May 12, 2022
I would be happy to work on this, but I don't really know where to begin.
uranusjr commentedon May 12, 2022
Simply search in
airflow/decorators/base.py:In class
_TaskDecorator(the one with a leading underscore), addIn class
TaskDecorator(the one without an underscore), addThe first class adds the actual property (so you can access this in tests), while the other declares the interface. The second one is not strictly necessary, but it’s good to provide it for editor autocompletion and stuff.
snjypl commentedon May 17, 2022
@uranusjr @ddeepwel do you mind if i create a PR for this?
uranusjr commentedon May 17, 2022
Go ahead