Skip to content

Invalidate cached Microsoft Graph request adapter on 403 Forbidden - #73601

Merged
shahar1 merged 4 commits into
apache:mainfrom
dabla:fix/msgraph-evict-adapter-on-403
Sep 23, 2026
Merged

shahar1 merged 4 commits into
apache:mainfrom
dabla:fix/msgraph-evict-adapter-on-403

Conversation

@dabla

@dabla dabla commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #72688, which started evicting the cached KiotaRequestAdapterHook request adapter when Microsoft Graph answers 401 Unauthorized.

Power BI reports an expired access token differently: 403 Forbidden with error code TokenExpired (documented here). With a Power BI connection on the msgraph connection type, the response handler turned that into a plain AirflowException, so nothing evicted the cached adapter. The adapter kept its credential and the stale token, and every retry of a deferred sensor such as a workspace scanStatus check replayed the same expired token until the triggerer process was restarted:

[2026-09-22T12:59:12.978705Z] INFO - Executing url 'myorg/admin/workspaces/scanStatus/bdd66c1f-...' as 'Method.GET'
[2026-09-22T12:59:12.979349Z] INFO - ClientSecretCredential.get_token succeeded
[2026-09-22T12:59:13.148507Z] ERROR - An error occurred: {'error': {'code': 'TokenExpired', 'message': 'Access token has expired, resubmit with a new access token'}}

DefaultResponseHandler now raises PermissionError for 403 as it does for 401, so send_request closes and evicts the cached adapter and the next call builds a fresh credential and token.

Tests: the send_request eviction test is parametrized over both status codes and a new response handler test covers a 403 TokenExpired body. The new handler test fails against the previous implementation.

Checks run locally: the msgraph hook, operator, sensor and trigger unit tests (145 passed, 1 xfailed) and prek run --from-ref upstream/main --stage pre-commit with check-provider-yaml-valid skipped (provider.yaml is untouched; that hook runs Breeze in Docker, which is not usable on my machine). The manual prek stage was not completed for the same reason.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Fable 5.1)

Generated-by: Claude Code (Fable 5.1) following the guidelines

… well

Power BI reports an expired access token as 403 Forbidden with error code
TokenExpired, unlike Microsoft Graph which answers 401 Unauthorized. The
request adapter cache only reacted to 401, so with a Power BI connection
the adapter kept its credential and the stale token, and every retry of a
deferred sensor such as a workspace scan status check replayed it until the
triggerer was restarted.

Treat 403 like 401 in the response handler, so send_request closes and
evicts the cached adapter and the next call builds a fresh credential and
token.
@dabla dabla self-assigned this Sep 23, 2026
@dabla
dabla requested review from eladkal and potiuk September 23, 2026 09:33
dabla and others added 3 commits September 23, 2026 11:42
The parametrized test is the only one with an annotated signature, so mypy
checks its body and rejects storing ``hook.api_version`` (``str | None``) in
``cached_request_adapters``, whose values are ``tuple[str, RequestAdapter]``.
Store the resolved ``"v1.0"`` literal like the other cache assertions do.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@shahar1
shahar1 merged commit 2e4a4b2 into apache:main Sep 23, 2026
83 checks passed
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.

2 participants