Skip to content

Conversation

@Fury0508
Copy link
Contributor

This PR migrates the remaining user endpoints from Connexion to FastAPI as part of #56730.

What's Changed

New endpoints in api_fastapi/routes/users.py:

  • GET /fab/v1/users - List users with pagination and ordering
  • GET /fab/v1/users/{username} - Get a single user by username
  • PATCH /fab/v1/users/{username} - Update user with update_mask support
  • DELETE /fab/v1/users/{username} - Delete a user

New datamodels in api_fastapi/datamodels/users.py:

  • UserPatchBody - Request model for partial updates (all fields optional)
  • UserCollectionResponse - Response model for paginated user list

New service methods in api_fastapi/services/users.py:

  • get_user() - Retrieve single user
  • get_users() - List users with pagination/ordering
  • update_user() - Partial update with update_mask support
  • delete_user() - Remove user

Tests added:

  • Route tests for all new endpoints (success, 403, 404, 422 cases)
  • Service layer tests covering all methods
  • Datamodel tests for UserPatchBody and UserCollectionResponse

Notes

  • Follows existing patterns from roles.py implementation
  • update_mask uses comma-separated string format (consistent with roles endpoint)
  • All 125 tests pass locally

closes #60946


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude following the guidelines

Claude was used for:

  • Code review and suggestions for implementation patterns
  • Writing test cases for routes, services, and datamodels
  • Debugging test environment setup issues

- Add GET /fab/v1/users (list with pagination/ordering)
- Add GET /fab/v1/users/{username}
- Add PATCH /fab/v1/users/{username} with update_mask support
- Add DELETE /fab/v1/users/{username}
- Add UserPatchBody and UserCollectionResponse datamodels
- Add comprehensive tests for routes, services, and datamodels

closes apache#60946
@henry3260
Copy link
Contributor

Thanks for the PR! I just have one question:

It seems user_endpoint.py hasn't been migrated to FastAPI yet, but the commit message says it has. Did we miss this file?

@Fury0508
Copy link
Contributor Author

Fury0508 commented Jan 23, 2026

Thanks for the PR! I just have one question:

It seems user_endpoint.py hasn't been migrated to FastAPI yet, but the commit message says it has. Did we miss this file?

Thanks for the question!

The new FastAPI endpoints have been created in api_fastapi/routes/users.py (you can see them in the "Files changed" tab):

  • GET /fab/v1/users
  • GET /fab/v1/users/{username}
  • PATCH /fab/v1/users/{username}
  • DELETE /fab/v1/users/{username}

The old Connexion file (api_endpoints/user_endpoint.py) is intentionally kept for now. This follows the same pattern as the roles migration (PR #58023) - create new FastAPI endpoints first, then remove old Connexion files in a separate cleanup PR after all migrations are complete.

The migration approach is:

  1. Create new FastAPI endpoints (this PR)
  2. Remove old Connexion endpoints (separate cleanup after Replace connexion with fast-api: role_and_permission_endpoint.py #60944, Replace connexion with fast-api: initialization, constants, exceptions, schemas. #60945 are done)

@vincbeck vincbeck changed the title Fab fastapi user endpoint Migrate Flask based user APIs to Fastapi Jan 23, 2026
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.

LGTM

@henry3260
Copy link
Contributor

Try running prek run --all-files locally, it should fix the formatting issues :)

@Fury0508
Copy link
Contributor Author

Try running prek run --all-files locally, it should fix the formatting issues :)

Thanks! Ran pre-commit run --all-files locally and pushed the fixes. Hopefully CI passes now 🤞

@Fury0508 Fury0508 requested a review from vincbeck January 23, 2026 18:11
@Fury0508
Copy link
Contributor Author

Fury0508 commented Jan 23, 2026

@vincbeck CI has 2 failing checks:

  1. UI E2E tests - I only modified backend API code, no frontend changes

  2. Compat 3.0.6 - The error "Status code 204 must not have a response body" occurs in ALL FAB FastAPI route tests:

    • test_login.py (3 errors) - not modified by me
    • test_roles.py (23 errors) - not modified by me
    • test_users.py (22 errors) - my changes

The error happens during test setup, suggesting a TestClient compatibility issue with Airflow 3.0.6, not my code.

Could you confirm if these are known issues? Happy to investigate further if needed.

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.

I guess the CI failed because returning None results in a null response body, but HTTP 204 responses must not have a body. Please return an empty Response object instead.

@Fury0508 Fury0508 requested a review from henry3260 January 23, 2026 21:53
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 fix. LGTM.

@vincbeck vincbeck merged commit 9d64edf into apache:main Jan 26, 2026
128 checks passed
@boring-cyborg
Copy link

boring-cyborg bot commented Jan 26, 2026

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

shreyas-dev pushed a commit to shreyas-dev/airflow that referenced this pull request Jan 29, 2026
* changes

* Replace connexion with FastAPI: user_endpoint.py

- Add GET /fab/v1/users (list with pagination/ordering)
- Add GET /fab/v1/users/{username}
- Add PATCH /fab/v1/users/{username} with update_mask support
- Add DELETE /fab/v1/users/{username}
- Add UserPatchBody and UserCollectionResponse datamodels
- Add comprehensive tests for routes, services, and datamodels

closes apache#60946
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.

Replace connexion with fast-api: user_endpoint.py

3 participants