Skip to content

Fix 500 Error in FAB API Users endpoint by allowing naive datetimes i…#62327

Merged
vincbeck merged 3 commits intoapache:mainfrom
anyeole:main
Feb 23, 2026
Merged

Fix 500 Error in FAB API Users endpoint by allowing naive datetimes i…#62327
vincbeck merged 3 commits intoapache:mainfrom
anyeole:main

Conversation

@anyeole
Copy link
Contributor

@anyeole anyeole commented Feb 22, 2026

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

  • Unit tests updated and verified.
  • Tested against a live Airflow 3.1.6 environment backed by MySQL (RDS) where the 500 error was successfully resolved.

Related Issues

Fixes: #62325

@anyeole anyeole requested a review from vincbeck as a code owner February 22, 2026 15:55
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 22, 2026

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

Copy link
Contributor

@henry3260 henry3260 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pr!

@anyeole anyeole requested a review from henry3260 February 23, 2026 08:36
Copy link
Contributor

@vincbeck vincbeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, let's see the CI

@henry3260
Copy link
Contributor

Since CI is passing, we don't really need to merge it manually.

@vincbeck vincbeck merged commit 524c8b5 into apache:main Feb 23, 2026
86 checks passed
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 23, 2026

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 500 Internal Server Error on /auth/fab/v1/users API due to Pydantic Timezone Validation (Airflow 3.1.6 + FAB 3.3.0)

3 participants