Skip to content

Fix 500 Internal Server Error when JWT user does not exist in FabAuth… - #61517

Merged
uranusjr merged 6 commits into
apache:mainfrom
MonsterChenzhuo:fix500
Feb 10, 2026
Merged

Fix 500 Internal Server Error when JWT user does not exist in FabAuth…#61517
uranusjr merged 6 commits into
apache:mainfrom
MonsterChenzhuo:fix500

Conversation

@MonsterChenzhuo

@MonsterChenzhuoMonsterChenzhuo commented Feb 6, 2026

Copy link
Copy Markdown
Contributor
image

Description

When using FabAuthManager, if a request contains a valid JWT token but the user ID inside the token (sub claim) does not exist in the database (e.g., the user was deleted), deserialize_user executes self.session.scalars(...).one(), which raises a sqlalchemy.exc.NoResultFound exception.

Currently, this exception is unhandled, causing the API to crash with a 500 Internal Server Error.

Error log:

Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: INFO: xxxxxxx:44100 - "GET /auth/login/?next= HTTP/1.1" 500 Internal Server Error
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: ERROR: Exception in ASGI application
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: + Exception Group Traceback (most recent call last):
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 416, in run_asgi
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | result = await app( # type: ignore[func-returns-value]
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/fastapi/applications.py", line 1082, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await super().__call__(scope, receive, send)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/applications.py", line 113, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await self.middleware_stack(scope, receive, send)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/middleware/errors.py", line 186, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | raise exc
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await self.app(scope, receive, _send)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/middleware/gzip.py", line 29, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await responder(scope, receive, send)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/middleware/gzip.py", line 130, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await super().__call__(scope, receive, send)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/middleware/gzip.py", line 46, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await self.app(scope, receive, self.send_with_compression)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/middleware/cors.py", line 85, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await self.app(scope, receive, send)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/middleware/base.py", line 189, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | raise app_exc
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/middleware/base.py", line 144, in coro
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await self.app(scope, receive_or_disconnect, send_no_error)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 63, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | raise exc
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await app(scope, receive, sender)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/routing.py", line 716, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await self.middleware_stack(scope, receive, send)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/routing.py", line 736, in app
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await route.handle(scope, receive, send)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/routing.py", line 462, in handle
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await self.app(scope, receive, send)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/fastapi/applications.py", line 1082, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await super().__call__(scope, receive, send)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/applications.py", line 113, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | await self.middleware_stack(scope, receive, send)
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | File "/data/airflow3env/lib/python3.12/site-packages/starlette/middleware/errors.py", line 186, in __call__
Feb 06 06:56:16 rpd-lhr-bd-prod-airflow-001 bash[103976]: | raise exc
Feb 06 06:56:16

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

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@shahar1shahar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! I added unit tests to avoid possible regressions in the future (used GitHub Copilot for generating).
Please note to add unit tests in your next PRs (I assisted this time as I want to include this PR in the upcoming release that I cut very soon)

@uranusjr
uranusjr merged commit e5ef1d0 into apache:mainFeb 10, 2026
86 checks passed
@jscheffljscheffl mentioned this pull request Feb 10, 2026
1 task
Alok-kumar-priyadarshi pushed a commit to Alok-kumar-priyadarshi/airflow that referenced this pull request Feb 11, 2026
apache#61517)
Co-authored-by: zhuoyuchen <>
Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
Ratasa143 pushed a commit to Ratasa143/airflow that referenced this pull request Feb 15, 2026
apache#61517)
Co-authored-by: zhuoyuchen <>
Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
choo121600 pushed a commit to choo121600/airflow that referenced this pull request Feb 22, 2026
apache#61517)
Co-authored-by: zhuoyuchen <>
Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
AkshayArali pushed a commit to AkshayArali/airflow_630 that referenced this pull request Feb 27, 2026
apache#61517)
Co-authored-by: zhuoyuchen <>
Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
AkshayArali pushed a commit to AkshayArali/airflow_630 that referenced this pull request Feb 27, 2026
apache#61517)
Co-authored-by: zhuoyuchen <>
Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
Subham-KRLX pushed a commit to Subham-KRLX/airflow that referenced this pull request Mar 4, 2026
apache#61517)
Co-authored-by: zhuoyuchen <>
Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
dominikhei pushed a commit to dominikhei/airflow that referenced this pull request Mar 11, 2026
apache#61517)
Co-authored-by: zhuoyuchen <>
Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
Ankurdeewan pushed a commit to Ankurdeewan/airflow that referenced this pull request Mar 15, 2026
apache#61517)
Co-authored-by: zhuoyuchen <>
Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
radhwene pushed a commit to radhwene/airflow that referenced this pull request Mar 21, 2026
apache#61517)
Co-authored-by: zhuoyuchen <>
Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
Sign up for freeto 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.

3 participants

@MonsterChenzhuo@uranusjr@shahar1