Copilot commented on code in PR #70225: URL: https://github.com/apache/airflow/pull/70225#discussion_r3630430122
########## providers/standard/src/airflow/providers/standard/triggers/asset.py: ########## @@ -0,0 +1,206 @@ +# 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 asyncio +from typing import TYPE_CHECKING, Any + +from asgiref.sync import sync_to_async + +from airflow.providers.common.compat.module_loading import import_string +from airflow.triggers.base import BaseTrigger, TriggerEvent + +if TYPE_CHECKING: + from collections.abc import AsyncIterator + from datetime import datetime + + +def _count_satisfied(count: int, expected_count: int) -> bool: + """ + Return whether the number of (processed) asset events satisfies the expectation. + + ``expected_count == -1`` means "at least one" (``count >= 1``); any other value + requires an exact match (``count == expected_count``). + """ + if expected_count == -1: + return count >= 1 + return count == expected_count + + +def _fetch_asset_events( + *, + name: str | None, + uri: str | None, + alias_name: str | None, + after: datetime | str | None, + before: datetime | str | None, + ascending: bool, + limit: int | None, + partition_key: str | None, + partition_key_regexp_pattern: str | None, + extra: dict[str, str] | None, +) -> list[Any]: + """ + Fetch asset events matching the given filters. + + This uses the Task SDK :class:`InletEventsAccessor`, which lazily fetches events + from the supervisor. It is a blocking call and must be wrapped with + ``sync_to_async`` when used from within the triggerer. + """ + from airflow.sdk.execution_time.context import InletEventsAccessor + + accessor = InletEventsAccessor(asset_name=name, asset_uri=uri, alias_name=alias_name) + if after is not None: + accessor.after(after) # type: ignore[arg-type] + if before is not None: + accessor.before(before) # type: ignore[arg-type] Review Comment: `InletEventsAccessor.after()`/`.before()` are typed to accept ISO strings, but this function accepts `datetime | str` and currently passes datetimes through with `# type: ignore`. Coerce non-string values to ISO strings here to keep the accessor contract intact and avoid suppressing type checks. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
