Skip to content

Improve error message for Python decorator invoking function with same name as the task name #49875

Closed

Description

@eladkal

Body

Given code:

from datetime import datetime
from airflow import DAG
from airflow.decorators import task
from time import sleep

default_args = {
    'owner': 'airflow',
    'start_date': datetime(2023, 2, 1)
}


with DAG('scheduler', schedule="@daily", catchup=True, default_args=default_args):

    @task()
    def sleep():
        sleep(3600)
    sleep()

It fails with:

TypeError: too many positional arguments

File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/task_runner.py", line 829 in run

File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/task_runner.py", line 1092 in _execute_task

File "/opt/airflow/task-sdk/src/airflow/sdk/bases/operator.py", line 408 in wrapper

File "/opt/airflow/task-sdk/src/airflow/sdk/bases/decorator.py", line 251 in execute

File "/opt/airflow/task-sdk/src/airflow/sdk/bases/operator.py", line 408 in wrapper

File "/opt/airflow/providers/standard/src/airflow/providers/standard/operators/python.py", line 212 in execute

File "/opt/airflow/providers/standard/src/airflow/providers/standard/operators/python.py", line 235 in execute_callable

File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/callback_runner.py", line 81 in run

File "/files/dags/scheduler.py", line 15 in sleep

File "/opt/airflow/task-sdk/src/airflow/sdk/bases/decorator.py", line 363 in __call__

File "/opt/airflow/task-sdk/src/airflow/sdk/bases/operator.py", line 513 in apply_defaults

File "/opt/airflow/providers/standard/src/airflow/providers/standard/decorators/python.py", line 58 in __init__

File "/opt/airflow/task-sdk/src/airflow/sdk/bases/operator.py", line 513 in apply_defaults

File "/opt/airflow/task-sdk/src/airflow/sdk/bases/decorator.py", line 239 in __init__

File "/usr/local/lib/python3.9/inspect.py", line 3045 in bind

File "/usr/local/lib/python3.9/inspect.py", line 2966 in _bind

The reason for this failure is because the python task has the exact name as the python function. My real code was more complex than the example I share here.. it took me several minutes to figure out what was the issue. Not sure if we can fix it but if we can improve the error message we should

Image

Committer

  • I acknowledge that I am a maintainer/committer of the Apache Airflow project.

Activity

  1. added theissue type on Apr 28, 2025
  2. giannistbs commented on Apr 28, 2025

    @giannistbs
    Contributor

    Hello! Can i work on this?

  3. ashb commented on Apr 28, 2025

    @ashb
    Member

    Hello! Can i work on this?

    What is your plan?

  4. kiran2706 commented on May 23, 2025

    @kiran2706
    Contributor

    @ashb - Can I take a shot at this?

    My plan is to implement it by intercepting function calls in TaskDecorator.call, and inspecting the call stack to detect potential self-invocations caused by naming collisions between the function and the task object.
    If detected, I'll log a clear warning or optionally raise an informative error to help users debug it faster.
    Let me know if you have any suggestions before I start

    cc: @potiuk

  5. vatsrahul1001 commented on Aug 28, 2025

    @vatsrahul1001
    Contributor

    I can repro this as well

  6. suman-himanshu commented on Aug 29, 2025

    @suman-himanshu
    Contributor

    I am able to reproduce this issue at my end.

    Image
  7. ashb commented on Sep 24, 2025

    @ashb
    Member

    @ashb - Can I take a shot at this?

    My plan is to implement it by intercepting function calls in TaskDecorator.call, and inspecting the call stack to detect potential self-invocations caused by naming collisions between the function and the task object. If detected, I'll log a clear warning or optionally raise an informative error to help users debug it faster. Let me know if you have any suggestions before I start

    Ideally though we do that without inspecting the callstack in "happy" path cases, as looking at the call stack is expensive.

  8. gitbita99 commented on Apr 8, 2026

    @gitbita99

    @ashb - Can I take a shot at this?
    My plan is to implement it by intercepting function calls in TaskDecorator.call, and inspecting the call stack to detect potential self-invocations caused by naming collisions between the function and the task object. If detected, I'll log a clear warning or optionally raise an informative error to help users debug it faster. Let me know if you have any suggestions before I start

    Ideally though we do that without inspecting the callstack in "happy" path cases, as looking at the call stack is expensive.

    Hi @ashb , I would like to work in this issue

    Problem: When users shadow imports with task name, they get a cryptic TypeError: too many positional arguments.

    Solution: Add exception handling in DecoratedOperator.__init__ to provide a helpful hint message - only when the error occurs (No overhead).

    The fix catches the TypeError during signature binding, adds guidance / hint and returns it.

    I have a working implementation ready. Could you please assign this issue to me?

  9. Gourigupta2004 commented on Jun 28, 2026

    @Gourigupta2004

    Hi @eladkal,

    I would like to investigate and work on this issue. Please assign this to me

    Thanks

  10. potiuk commented on Jun 29, 2026

    @potiuk
    Member

    We do not assign issues (see contributing guides) - but feel free to work on it.

  11. 66 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions