anyeole opened a new pull request, #62327:
URL: https://github.com/apache/airflow/pull/62327

   <!--
   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
   ... (Keep the standard Apache license block at the top when you create the 
PR) ...
   -->
   
   ### Description
   This PR resolves a **500 Internal Server Error** that occurs when hitting 
the FastAPI `GET /auth/fab/v1/users` endpoint on a live database (e.g., MySQL 
or Postgres).
   
   **The Issue:**
   The new Pydantic 
[UserResponse](cci:2://file://airflow/providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/datamodels/users.py:48:0-61:47)
 datamodel was overly strict, enforcing [UtcDateTime] for the `last_login`, 
`created_on`, and `changed_on` fields.
   Because the FAB provider inherits its SQLAlchemy models directly from 
`Flask-AppBuilder` for legacy compatibility, the [ab_user] database schema 
defines these fields using standard naive `sqlalchemy.DateTime`. 
   
   When SQLAlchemy retrieves these rows from MySQL/Postgres, it returns naive 
`datetime.datetime` objects. Pydantic immediately rejects these naive 
datetimes, crashing the API.
   
   **Why this bypassed CI:**
   The existing unit tests for the `/users` routes used Python mocks where 
these timestamp fields were completely omitted (`None` is permitted by the 
schema), meaning the strict `UtcDateTime` validation logic was never tested 
against standard naive SQLAlchemy database objects.
   
   **The Fix:**
   - Downgraded `UtcDateTime` to strict `datetime.datetime` inside the 
`UserResponse` schema 
(`providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/datamodels/users.py`)
 so it properly aligns with the actual SQLAlchemy `User` model output.
   - Updated 
`providers/fab/tests/unit/fab/auth_manager/api_fastapi/datamodels/test_users.py`
 to ensure naive datetimes are correctly preserved rather than strictly coerced 
or rejected.
   
   ### Testing/Verification
   - [x] Unit tests updated and verified.
   - [x] Tested against a live Airflow 3.1.6 environment backed by MySQL (RDS) 
where the 500 error was successfully resolved.
   
   ### Related Issues
   Fixes: #62325 
   


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