pierrejeambrun commented on code in PR #68833:
URL: https://github.com/apache/airflow/pull/68833#discussion_r3493247211


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/event_logs.py:
##########
@@ -54,6 +56,65 @@
 event_logs_router = AirflowRouter(tags=["Event Log"], prefix="/eventLogs")
 
 
+def _get_user_display_name(user) -> str:
+    """Return the most readable identity label available for audit logs."""
+    first_name = (getattr(user, "first_name", None) or "").strip()
+    last_name = (getattr(user, "last_name", None) or "").strip()
+    email = (getattr(user, "email", None) or "").strip()
+    username = (getattr(user, "username", None) or "").strip()
+
+    if first_name and last_name and last_name != "-":
+        return f"{first_name} {last_name}"
+    if email:
+        return email
+    return username
+
+
+def _get_owner_display_names_by_owner(owners: Iterable[str | None], session: 
Session) -> dict[str, str]:
+    owner_values = {owner for owner in owners if owner}
+    if not owner_values:
+        return {}
+
+    try:
+        from airflow.providers.fab.auth_manager.models import User
+    except ImportError:
+        return {}
+
+    try:
+        users = session.scalars(
+            select(User).where(or_(User.username.in_(owner_values), 
User.email.in_(owner_values)))
+        )
+    except SQLAlchemyError:
+        session.rollback()
+        return {}

Review Comment:
   No manual rollback, session lifecycle is handled by the app 



##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/event_logs.py:
##########
@@ -54,6 +56,65 @@
 event_logs_router = AirflowRouter(tags=["Event Log"], prefix="/eventLogs")
 
 
+def _get_user_display_name(user) -> str:
+    """Return the most readable identity label available for audit logs."""
+    first_name = (getattr(user, "first_name", None) or "").strip()
+    last_name = (getattr(user, "last_name", None) or "").strip()
+    email = (getattr(user, "email", None) or "").strip()
+    username = (getattr(user, "username", None) or "").strip()
+
+    if first_name and last_name and last_name != "-":
+        return f"{first_name} {last_name}"
+    if email:
+        return email
+    return username
+
+
+def _get_owner_display_names_by_owner(owners: Iterable[str | None], session: 
Session) -> dict[str, str]:
+    owner_values = {owner for owner in owners if owner}
+    if not owner_values:
+        return {}
+
+    try:
+        from airflow.providers.fab.auth_manager.models import User
+    except ImportError:
+        return {}
+
+    try:
+        users = session.scalars(
+            select(User).where(or_(User.username.in_(owner_values), 
User.email.in_(owner_values)))
+        )
+    except SQLAlchemyError:
+        session.rollback()
+        return {}

Review Comment:
   No manual rollback, session lifecycle is handled by the app  / request dep



-- 
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]

Reply via email to