Misleading Warning: "Custom Operator Inheriting from SageMakerTrainingOperator Incorrectly Triggers execute cannot be called outside TaskInstance" #45498
Labels
area:providers
kind:bug
This is a clearly a bug
needs-triage
label for new issues that we didn't triage yet
provider:amazon-aws
AWS/Amazon - related issues
Apache Airflow Provider(s)
amazon
Versions of Apache Airflow Providers
8.28.0
Apache Airflow version
2.10.2
Operating System
ubuntu
Deployment
Docker-Compose
Deployment details
No response
What happened
We have created a custom operator,
CustomSageMakerTrainingOperator
, that inherits fromSageMakerTrainingOperator
. Although the operator is executed within a proper TaskInstance context, we receive a persistent and seemingly incorrect warning in the logs:[2025-01-03, 22:57:16 UTC] {baseoperator.py:405} WARNING - CustomSageMakerTrainingOperator.execute cannot be called outside TaskInstance!
This warning appears even though our operator’s
execute
method is only called as part of a TaskInstance execution. The operator code, which extends the functionality ofSageMakerTrainingOperator
, confirms that no misuse exists. This suggests that the warning is a false positive, potentially due to an issue within Airflow’s internals handling of such inherited operators.What you think should happen instead
The custom operator should run the SageMaker training job without generating the misleading warning, since the
execute
is indeed called in a validTaskInstance
context.How to reproduce
The custom operator should run the SageMaker training job without generating the misleading warning. The warning should not appear when the
execute
method is correctly invoked within a TaskInstance context. Ideally, Airflow should correctly assess the context for inherited operators likeCustomSageMakerTrainingOperator
and refrain from showing this warning.Anything else
Below is the core of the custom operator code (anonymized). Full code snippet is in the original text:
I've tried to confirm that the execute method is only invoked via a TaskInstance, so I'm not sure why the warning triggers. Possibly there's a check in baseoperator.py or within SageMakerTrainingOperator that incorrectly flags this scenario.
Potential Evaluated Solutions:
Investigate if the super().init call with config=self.config is triggering unexpected logic in SageMakerTrainingOperator.
Check if there's an internal method or property in SageMakerTrainingOperator that must be overridden or called differently.
Possibly a bug in the logic that triggers the “outside TaskInstance” warning for operators inheriting from SageMakerTrainingOperator.
Are you willing to submit PR?
Code of Conduct
The text was updated successfully, but these errors were encountered: