bbovenzi commented on code in PR #68833: URL: https://github.com/apache/airflow/pull/68833#discussion_r3639055294
########## airflow-core/src/airflow/api_fastapi/core_api/services/public/event_logs.py: ########## @@ -0,0 +1,52 @@ +# 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 + +from sqlalchemy import inspect +from sqlalchemy.orm.attributes import set_committed_value + +from airflow.api_fastapi.auth.managers.models.base_user import BaseUser +from airflow.api_fastapi.core_api.datamodels.event_logs import EventLogResponse +from airflow.models import Log + + +def _resolve_owner_display_name(event_log: Log, user: BaseUser | None) -> str | None: + if event_log.owner_display_name: + return event_log.owner_display_name + if not event_log.owner: + return None + if user is not None and event_log.owner == user.get_name(): + return user.get_name() + return event_log.owner + + +def _prepare_event_log_for_response(event_log: Log, *, owner_display_name: str | None) -> None: + # Response-only fallbacks must not make the ORM object dirty at request commit time. + set_committed_value(event_log, "owner_display_name", owner_display_name) + + unloaded: set[str] = inspect(event_log).unloaded + for relationship_name in ("dag_model", "task_instance"): Review Comment: Can we add a test case to make sure we're not losing dag_display_name or task_display_name when clearing unloaded relationships? -- 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]
