Skip to content

Conversation

@kaxil
Copy link
Member

@kaxil kaxil commented Sep 17, 2025

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executorversion_compatBaseOperatortaskinstancesentryexecutor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:

  • Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
  • Add conditional imports directly in operator/sensor files that need these classes
  • Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Fixes #55810


To Reproduce:

❯ docker run --rm apache/airflow:2.11.0 bash -c 'pip install sentry-sdk apache-airflow-providers-cncf-kubernetes==10.6.1
export AIRFLOW__CORE__EXECUTOR="KubernetesExecutor"
export AIRFLOW__SENTRY__SENTRY_ON="True"
export AIRFLOW__SENTRY__SENTRY_DSN="https://fake@fake.ingest.sentry.io/fake"
export AIRFLOW__DATABASE__SQL_ALCHEMY_CONN="postgresql://fake:fake@fake:5432/Sentry enabled (sentry_on=True)"

python3 -c "import airflow.providers.cncf.kubernetes.executors.kubernetes_executor"
'

Error log:

Collecting sentry-sdk
  ...

/home/airflow/.local/lib/python3.12/site-packages/airflow/metrics/base_stats_logger.py:22 RemovedInAirflow3Warning: Timer and timing metrics publish in seconds were deprecated. It is enabled by default from Airflow 3 onwards. Enable timer_unit_consistency to publish all the timer and timing metrics in milliseconds.
Traceback (most recent call last):
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/module_loading.py", line 42, in import_string
    return getattr(module, class_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: partially initialized module 'airflow.providers.cncf.kubernetes.executors.kubernetes_executor' has no attribute 'KubernetesExecutor' (most likely due to a circular import)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py", line 43, in <module>
    from airflow.providers.cncf.kubernetes.pod_generator import PodGenerator
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/cncf/kubernetes/pod_generator.py", line 49, in <module>
    from airflow.providers.cncf.kubernetes.version_compat import AIRFLOW_V_3_0_PLUS
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/cncf/kubernetes/version_compat.py", line 41, in <module>
    from airflow.models import BaseOperator  # type: ignore[no-redef]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/models/__init__.py", line 79, in __getattr__
    val = import_string(f"{path}.{name}")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/module_loading.py", line 39, in import_string
    module = import_module(module_path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/models/baseoperator.py", line 83, in <module>
    from airflow.models.mappedoperator import OperatorPartial, validate_mapping_kwargs
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/models/mappedoperator.py", line 54, in <module>
    from airflow.triggers.base import StartTriggerArgs
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/triggers/base.py", line 27, in <module>
    from airflow.models.taskinstance import SimpleTaskInstance
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/models/taskinstance.py", line 106, in <module>
    from airflow.sentry import Sentry
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sentry.py", line 196, in <module>
    Sentry = ConfiguredSentry()
             ^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sentry.py", line 88, in __init__
    executor_class, _ = ExecutorLoader.import_default_executor_cls(validate=False)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/executors/executor_loader.py", line 314, in import_default_executor_cls
    executor, source = cls.import_executor_cls(executor_name, validate=validate)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/executors/executor_loader.py", line 302, in import_executor_cls
    return _import_and_validate(executor_name.module_path), executor_name.connector_source
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/executors/executor_loader.py", line 286, in _import_and_validate
    executor = import_string(path)
               ^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/module_loading.py", line 44, in import_string
    raise ImportError(f'Module "{module_path}" does not define a "{class_name}" attribute/class')
ImportError: Module "airflow.providers.cncf.kubernetes.executors.kubernetes_executor" does not define a "KubernetesExecutor" attribute/class

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
@kaxil kaxil force-pushed the fix-circular-import-ke branch from 7cb2ad6 to 48cb640 Compare September 17, 2025 23:16
@kaxil kaxil merged commit ca9f3f0 into apache:main Sep 17, 2025
78 of 84 checks passed
@kaxil kaxil deleted the fix-circular-import-ke branch September 17, 2025 23:57
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Sep 30, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 1, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 2, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 3, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 4, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 5, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 5, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 7, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 8, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 9, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 10, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 11, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 12, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 14, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 15, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 17, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

Fixes apache#55803
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 19, 2025
…e#55809)

Resolves circular import that occurs when KubernetesExecutor is dynamically loaded during Airflow startup. The issue manifests as 'cannot import name from partially initialized module' errors during scheduler/triggerer initialization.

Root cause: The import chain executor → version_compat → BaseOperator → taskinstance → sentry → executor creates a circular dependency when sentry is enabled, as sentry initialization attempts to load the executor while it's already being imported.

Changes:
- Remove BaseOperator and BaseSensorOperator from version_compat.py module-level imports
- Add conditional imports directly in operator/sensor files that need these classes
- Maintain compatibility across Airflow 2.x and 3.x versions

This prevents the circular import by breaking the chain at version_compat, ensuring sentry initialization doesn't trigger recursive executor loading.

Files affected:
- version_compat.py: Removed BaseOperator/BaseSensorOperator imports
- operators/job.py: Added conditional BaseOperator import
- operators/kueue.py: Added conditional BaseOperator import
- operators/pod.py: Added conditional BaseOperator import
- operators/resource.py: Added conditional BaseOperator import
- sensors/spark_kubernetes.py: Added conditional BaseSensorOperator import

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

Labels

area:providers provider:cncf-kubernetes Kubernetes (k8s) provider related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scheduler using KubernetesExecutor crashes when sentry-sdk is installed and enabled

3 participants