Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion providers/apache/iceberg/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ requires-python = ">=3.10"
# After you modify the dependencies, and rebuild your Breeze CI image with ``breeze ci-image build``
dependencies = [
"apache-airflow>=2.11.0",
"apache-airflow-providers-common-compat>=1.8.0",
"apache-airflow-providers-common-compat>=1.8.0", # use next version
"pyiceberg>=0.8.0",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@
from pyiceberg.exceptions import NoSuchNamespaceError, NoSuchTableError

from airflow.providers.apache.iceberg.hooks.iceberg import IcebergHook
from airflow.providers.apache.iceberg.version_compat import AIRFLOW_V_3_0_PLUS

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,
)
from airflow.providers.common.compat.triggers import BaseEventTrigger
from airflow.triggers.base import TriggerEvent

if TYPE_CHECKING:
from collections.abc import AsyncIterator
Expand Down
Original file line number Diff line number Diff line change
@@ -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())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

36 changes: 36 additions & 0 deletions providers/common/compat/tests/unit/common/compat/test_triggers.py
Original file line number Diff line number Diff line change
@@ -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

def test_unknown_attribute_raises(self):
with pytest.raises(AttributeError, match="module has no attribute 'NotATrigger'"):
triggers.NotATrigger