Repository navigation
Invalidate cached Microsoft Graph request adapter on 403 Forbidden - #73601
Merged
Merged
Conversation
… 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.
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
approved these changes
Sep 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #72688, which started evicting the cached
KiotaRequestAdapterHookrequest adapter when Microsoft Graph answers401 Unauthorized.Power BI reports an expired access token differently:
403 Forbiddenwith error codeTokenExpired(documented here). With a Power BI connection on themsgraphconnection type, the response handler turned that into a plainAirflowException, 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 workspacescanStatuscheck replayed the same expired token until the triggerer process was restarted:DefaultResponseHandlernow raisesPermissionErrorfor403as it does for401, sosend_requestcloses and evicts the cached adapter and the next call builds a fresh credential and token.Tests: the
send_requesteviction test is parametrized over both status codes and a new response handler test covers a403 TokenExpiredbody. 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-commitwithcheck-provider-yaml-validskipped (provider.yamlis 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?
Generated-by: Claude Code (Fable 5.1) following the guidelines