dabla commented on code in PR #74673: URL: https://github.com/apache/airflow/pull/74673#discussion_r4335014858
########## providers/common/compat/src/airflow/providers/common/compat/_resumable_job_mixin.py: ########## @@ -0,0 +1,58 @@ +# 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. +""" +Stand-in for ``airflow.sdk.ResumableJobMixin`` on Airflow versions below 3.3. + +``ResumableJobMixin`` and the ``task_state_store`` it relies on arrived in Airflow 3.3. An operator +that imports the mixin from :mod:`airflow.providers.common.compat.sdk` keeps working on older +versions: this stand-in submits a new job on every try, exactly what the operator did before it +became durable. That module tries the SDK first, so on 3.3 and later it hands out the SDK class and +this one is never imported. +""" + +from __future__ import annotations + +import warnings +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from airflow.sdk.definitions.context import Context + +# Tells "durable left at its default" apart from an explicit durable=True/False, so only an explicit +# value warns that it has no effect here. +_DURABLE_UNSET: Any = object() + + +class ResumableJobMixin: + """Airflow < 3.3 stand-in: no ``task_state_store`` to resume from, so every try submits a new job.""" + + external_id_key: str = "remote_job_id" + + def __init__(self, *, durable: bool = _DURABLE_UNSET, **kwargs: Any) -> None: Review Comment: Thanks, follow-up in #75271. I went with `durable: bool | None = None` instead of `bool | Any` or `Any`: a union with `Any` turns off type checking for the argument just like `Any`, and `None` is already what every provider operator uses for "not set" (they only forward `durable` when it is not `None`), so the stand-in now follows the same convention and stays type-checked. -- 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]
