You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "amoghrajesh (via GitHub)" <gi...@apache.org> on 2026/08/27 10:10:56 UTC

[PR] Add common.compat alias for BaseEventTrigger [airflow]

amoghrajesh opened a new pull request, #72140:
URL: https://github.com/apache/airflow/pull/72140

    <!-- SPDX-License-Identifier: Apache-2.0
         https://www.apache.org/licenses/LICENSE-2.0 -->
   
   <!--
   Thank you for contributing!
   
   Please provide above a brief description of the changes made in this pull request.
   Write a good git commit message following this guide: https://chris.beams.io/posts/git-commit/
   
   Please make sure that your code changes are covered with tests.
   And in case of new features or big changes remember to adjust the documentation.
   
   For user-facing UI changes, please attach before/after screenshots (or a short
   screen recording) so reviewers can assess the visual impact.
   
   Feel free to ping (in general) for the review if you do not see reaction for a few days
   (72 Hours is the minimum reaction time you can expect from volunteers) - we sometimes miss notifications.
   
   In case of an existing issue, reference it using one of the following:
   
   * closes: #ISSUE
   * related: #ISSUE
   -->
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, please
   change below checkbox to `[X]` followed by the name of the tool, uncomment the "Generated-by".
   -->
   
   - [ ] Yes (please specify the tool below)
   
   <!--
   Generated-by: [Tool Name] following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   -->
   
   
   
   Each provider repeats a variant of:
   
   ```python
   if AIRFLOW_V_3_0_PLUS:
       from airflow.triggers.base import BaseEventTrigger, TriggerEvent
   else:
       from airflow.triggers.base import (  # type: ignore[assignment]
           BaseTrigger as BaseEventTrigger,
           TriggerEvent,
       )
   ```
   
   Several of these also drag `TriggerEvent` into the version branch even though it exists in both 2.x and 3.x, and pull in an `AIRFLOW_V_3_0_PLUS` import that isn't used elsewhere.
   
   
   
   I am proposing that we add a `airflow.providers.common.compat.triggers`, which resolves `BaseEventTrigger` through the existing `create_module_getattr` rename machinery and falls back to `BaseTrigger` on Airflow 2.x. Call sites collapse to a single import.
   
   The iceberg trigger is migrated as the first consumer: https://github.com/apache/airflow/pull/71387/
   
   ---
   
   * Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: `{pr_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments). You can add this file in a follow-up commit after the PR is created so you know the PR number.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add common.compat alias for BaseEventTrigger [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #72140:
URL: https://github.com/apache/airflow/pull/72140#discussion_r3964979269


##########
providers/common/compat/tests/unit/common/compat/test_triggers.py:
##########
@@ -0,0 +1,36 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+import pytest
+
+import airflow.triggers.base
+from airflow.providers.common.compat import triggers
+
+
+class TestBaseEventTrigger:
+    def test_falls_back_to_base_trigger_without_base_event_trigger(self, monkeypatch):
+        """On Airflow 2.x, where the class does not exist, the alias resolves to BaseTrigger."""
+        # Already absent when the tests run against Airflow 2.x, which is the case being simulated.
+        monkeypatch.delattr(airflow.triggers.base, "BaseEventTrigger", raising=False)
+
+        assert triggers.BaseEventTrigger is airflow.triggers.base.BaseTrigger

Review Comment:
   Handled in [handling review comments from jason and kaxil](https://github.com/apache/airflow/pull/72140/commits/13c938e5c4dd24eaf35690da583713d9117bbe51)



##########
providers/common/compat/src/airflow/providers/common/compat/triggers.py:
##########
@@ -0,0 +1,38 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Compatibility imports for core trigger base classes across Airflow 2 and Airflow 3."""
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+
+from airflow.providers.common.compat._compat_utils import create_module_getattr
+
+if TYPE_CHECKING:
+    from airflow.triggers.base import BaseEventTrigger as BaseEventTrigger
+
+
+# Airflow 3.0 added BaseEventTrigger to mark triggers usable as event-driven scheduling sources.
+# Airflow 2.x has no such marker, so it falls back to BaseTrigger: subclasses still work as
+# deferred triggers there, they just cannot drive an asset watcher.
+_RENAME_MAP: dict[str, tuple[str, str, str]] = {
+    "BaseEventTrigger": ("airflow.triggers.base", "airflow.triggers.base", "BaseTrigger"),
+}
+
+__getattr__ = create_module_getattr(import_map={}, rename_map=_RENAME_MAP)
+
+__all__ = sorted(_RENAME_MAP.keys())

Review Comment:
   Handled in [handling review comments from jason and kaxil](https://github.com/apache/airflow/pull/72140/commits/13c938e5c4dd24eaf35690da583713d9117bbe51)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add common.compat alias for BaseEventTrigger [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #72140:
URL: https://github.com/apache/airflow/pull/72140#discussion_r3964973583


##########
providers/common/compat/tests/unit/common/compat/test_triggers.py:
##########
@@ -0,0 +1,36 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+import pytest
+
+import airflow.triggers.base
+from airflow.providers.common.compat import triggers
+
+
+class TestBaseEventTrigger:
+    def test_falls_back_to_base_trigger_without_base_event_trigger(self, monkeypatch):
+        """On Airflow 2.x, where the class does not exist, the alias resolves to BaseTrigger."""
+        # Already absent when the tests run against Airflow 2.x, which is the case being simulated.
+        monkeypatch.delattr(airflow.triggers.base, "BaseEventTrigger", raising=False)
+
+        assert triggers.BaseEventTrigger is airflow.triggers.base.BaseTrigger

Review Comment:
   Good catch. Added a test that asserts `triggers.BaseEventTrigger` is `airflow.triggers.base.BaseEventTrigger` directly, guarded with `@pytest.mark.skipif(not AIRFLOW_V_3_0_PLUS, ...)`, so a typo in `_RENAME_MAP` would now fail on the AF3 side.
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add common.compat alias for BaseEventTrigger [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #72140:
URL: https://github.com/apache/airflow/pull/72140#discussion_r3964967871


##########
providers/common/compat/src/airflow/providers/common/compat/triggers.py:
##########
@@ -0,0 +1,38 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Compatibility imports for core trigger base classes across Airflow 2 and Airflow 3."""
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+
+from airflow.providers.common.compat._compat_utils import create_module_getattr
+
+if TYPE_CHECKING:
+    from airflow.triggers.base import BaseEventTrigger as BaseEventTrigger
+
+
+# Airflow 3.0 added BaseEventTrigger to mark triggers usable as event-driven scheduling sources.
+# Airflow 2.x has no such marker, so it falls back to BaseTrigger: subclasses still work as
+# deferred triggers there, they just cannot drive an asset watcher.
+_RENAME_MAP: dict[str, tuple[str, str, str]] = {
+    "BaseEventTrigger": ("airflow.triggers.base", "airflow.triggers.base", "BaseTrigger"),
+}
+
+__getattr__ = create_module_getattr(import_map={}, rename_map=_RENAME_MAP)
+
+__all__ = sorted(_RENAME_MAP.keys())

Review Comment:
   Good catch, made the change to remove it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add common.compat alias for BaseEventTrigger [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #72140:
URL: https://github.com/apache/airflow/pull/72140#discussion_r3878247791


##########
providers/common/compat/src/airflow/providers/common/compat/triggers.py:
##########
@@ -0,0 +1,38 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Compatibility imports for core trigger base classes across Airflow 2 and Airflow 3."""
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+
+from airflow.providers.common.compat._compat_utils import create_module_getattr
+
+if TYPE_CHECKING:
+    from airflow.triggers.base import BaseEventTrigger as BaseEventTrigger
+
+
+# Airflow 3.0 added BaseEventTrigger to mark triggers usable as event-driven scheduling sources.
+# Airflow 2.x has no such marker, so it falls back to BaseTrigger: subclasses still work as
+# deferred triggers there, they just cannot drive an asset watcher.
+_RENAME_MAP: dict[str, tuple[str, str, str]] = {
+    "BaseEventTrigger": ("airflow.triggers.base", "airflow.triggers.base", "BaseTrigger"),
+}
+
+__getattr__ = create_module_getattr(import_map={}, rename_map=_RENAME_MAP)
+
+__all__ = sorted(_RENAME_MAP.keys())

Review Comment:
   tiny nit: Do we need to remove the `sorted` call here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add common.compat alias for BaseEventTrigger [airflow]

Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #72140:
URL: https://github.com/apache/airflow/pull/72140#discussion_r3963876279


##########
providers/common/compat/tests/unit/common/compat/test_triggers.py:
##########
@@ -0,0 +1,36 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+import pytest
+
+import airflow.triggers.base
+from airflow.providers.common.compat import triggers
+
+
+class TestBaseEventTrigger:
+    def test_falls_back_to_base_trigger_without_base_event_trigger(self, monkeypatch):
+        """On Airflow 2.x, where the class does not exist, the alias resolves to BaseTrigger."""
+        # Already absent when the tests run against Airflow 2.x, which is the case being simulated.
+        monkeypatch.delattr(airflow.triggers.base, "BaseEventTrigger", raising=False)
+
+        assert triggers.BaseEventTrigger is airflow.triggers.base.BaseTrigger

Review Comment:
   No test covers the Airflow 3 side, and the fallback makes that gap matter: `create_module_getattr` catches `AttributeError`/`ImportError` from the new path and returns the old name instead, so a typo in the first element of `_RENAME_MAP` would resolve `BaseEventTrigger` to `BaseTrigger` on Airflow 3 with both of these tests still green. `triggerer_job_runner` gates the watcher path on `isinstance(trigger_instance, BaseEventTrigger)`, so an Iceberg watcher would just stop firing. Worth adding an `AIRFLOW_V_3_0_PLUS`-guarded assert that the alias is `airflow.triggers.base.BaseEventTrigger`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add common.compat alias for BaseEventTrigger [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh merged PR #72140:
URL: https://github.com/apache/airflow/pull/72140


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org