This is an automated email from the ASF dual-hosted git repository.

vincbeck pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 524c8b5209f Fix 500 Error in FAB API Users endpoint by allowing naive 
datetimes i… (#62327)
524c8b5209f is described below

commit 524c8b5209ff58dde85fea60ca5945d5e520db0d
Author: anyeole <[email protected]>
AuthorDate: Mon Feb 23 22:37:28 2026 +0530

    Fix 500 Error in FAB API Users endpoint by allowing naive datetimes i… 
(#62327)
---
 .../fab/auth_manager/api_fastapi/datamodels/users.py     |  9 +++++----
 .../auth_manager/api_fastapi/datamodels/test_users.py    | 16 +++++++---------
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git 
a/providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/datamodels/users.py
 
b/providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/datamodels/users.py
index 9f9b7473439..2cbece47692 100644
--- 
a/providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/datamodels/users.py
+++ 
b/providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/datamodels/users.py
@@ -16,9 +16,10 @@
 # under the License.
 from __future__ import annotations
 
+from datetime import datetime
+
 from pydantic import Field, SecretStr
 
-from airflow.api_fastapi.common.types import UtcDateTime
 from airflow.api_fastapi.core_api.base import BaseModel, StrictBaseModel
 from airflow.providers.fab.auth_manager.api_fastapi.datamodels.roles import 
Role
 
@@ -54,11 +55,11 @@ class UserResponse(BaseModel):
     last_name: str
     roles: list[Role] | None = None
     active: bool | None = None
-    last_login: UtcDateTime | None = None
+    last_login: datetime | None = None
     login_count: int | None = None
     fail_login_count: int | None = None
-    created_on: UtcDateTime | None = None
-    changed_on: UtcDateTime | None = None
+    created_on: datetime | None = None
+    changed_on: datetime | None = None
 
 
 class UserCollectionResponse(BaseModel):
diff --git 
a/providers/fab/tests/unit/fab/auth_manager/api_fastapi/datamodels/test_users.py
 
b/providers/fab/tests/unit/fab/auth_manager/api_fastapi/datamodels/test_users.py
index a2c0648b197..c5b37c7ffa3 100644
--- 
a/providers/fab/tests/unit/fab/auth_manager/api_fastapi/datamodels/test_users.py
+++ 
b/providers/fab/tests/unit/fab/auth_manager/api_fastapi/datamodels/test_users.py
@@ -99,22 +99,22 @@ class TestUserModels:
                 }
             )
 
-    def test_userresponse_coerces_naive_datetimes_to_utc(self):
-        utc_created = datetime(2025, 1, 2, 3, 4, 5, tzinfo=timezone.utc)
+    def test_userresponse_accepts_naive_datetimes(self):
+        naive_created = datetime(2025, 1, 2, 3, 4, 5)
         resp = UserResponse.model_validate(
             {
                 "username": "alice",
                 "email": "[email protected]",
                 "first_name": "Alice",
                 "last_name": "Liddell",
-                "created_on": utc_created,
+                "created_on": naive_created,
             }
         )
         assert resp.created_on is not None
-        assert resp.created_on.utcoffset() == timedelta(0)
-        assert resp.created_on.replace(tzinfo=None) == 
utc_created.replace(tzinfo=None)
+        assert resp.created_on.tzinfo is None
+        assert resp.created_on == naive_created
 
-    def test_userresponse_preserves_aware_datetimes(self):
+    def test_userresponse_accepts_aware_datetimes(self):
         aware = datetime(2024, 12, 1, 9, 30, 
tzinfo=timezone(timedelta(hours=9)))
         resp = UserResponse.model_validate(
             {
@@ -125,9 +125,7 @@ class TestUserModels:
                 "changed_on": aware,
             }
         )
-        expected_utc = aware.astimezone(timezone.utc)
-        assert resp.changed_on.utcoffset() == timedelta(0)
-        assert resp.changed_on.timestamp() == expected_utc.timestamp()
+        assert resp.changed_on == aware
 
     def test_userresponse_model_validate_from_simple_namespace(self):
         obj = types.SimpleNamespace(

Reply via email to