Skip to content

Undesired "<SomeOperator>.execute cannot be called outside TaskInstance!" warning #39413

@zhaow-de

Description

@zhaow-de

Apache Airflow version

2.9.0

If "Other Airflow 2 version" selected, which one?

No response

What happened?

Decorated operators using the classic API trigger warning message ".execute cannot be called outside TaskInstance!"

What you think should happen instead?

PR #37937 introduced a new check to avoid the mixed usage of classic and decorated operators. Because a boundary condition of checking the decorators is missing, the operators cannot be decorated if a DAG uses the classic API.

Hopefully, the check should only be triggered if the operator is decorated with airflow.decorators.task

How to reproduce

Run the DAG below:

from airflow import DAG
from airflow.operators.python import PythonOperator


def deco(cls):
    orig_init = cls.__init__

    def new_init(self, *args, default_args=None, **kwargs):
        orig_init(self, *args, **kwargs)
        self.default_args = default_args

    cls.__init__ = cls._apply_defaults(new_init)
    return cls


@deco
class AlloyPythonOperator(PythonOperator):
    def execute(self, context):
        super().execute(context)


def no_ops():
    pass


with DAG(
    dag_id="test-dag",
    catchup=False,
):
    AlloyPythonOperator(
        task_id="trigger-execute",
        python_callable=no_ops,
    )

Operating System

Ubuntu 22.04 LTS, but the issue is OS independant

Versions of Apache Airflow Providers

core

Deployment

Other Docker-based deployment

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corekind:bugThis is a clearly a bugneeds-triagelabel for new issues that we didn't triage yetpending-responsestaleStale PRs per the .github/workflows/stale.yml policy file

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions