ashb commented on code in PR #69397: URL: https://github.com/apache/airflow/pull/69397#discussion_r3558403532
########## airflow-ctl/src/airflowctl/ctl/utils/dag_run.py: ########## @@ -0,0 +1,63 @@ +# 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 datetime +from typing import TYPE_CHECKING + +from airflowctl.api.client import ServerResponseError + +if TYPE_CHECKING: + from airflowctl.api.client import Client + from airflowctl.api.datamodels.generated import DAGRunResponse + + +def _parse_logical_date(value: str) -> datetime.datetime | None: + """Parse an ISO-formatted logical date.""" + try: + logical_date = datetime.datetime.fromisoformat(value.replace("Z", "+00:00")) + except ValueError: + return None + if logical_date.tzinfo is None: + raise SystemExit("Logical date must include a timezone offset") + return logical_date + + +def get_dag_run_by_run_id_or_logical_date( + api_client: Client, dag_id: str, value: str +) -> DAGRunResponse | None: + """Get a Dag run by run ID, falling back to an exact logical date match.""" + try: + return api_client.dag_runs.get(dag_id=dag_id, dag_run_id=value, suppress_error_log=True) + except ServerResponseError as e: + if e.response.status_code != 404: + raise Review Comment: I don't really like this approach -- why do we have one parameter that accepts two different values? It would be better to have different params, and that way when a run_id is given we don't need to make this extra, otherwise un-necessary request to check if the run exists. -- 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]
