Skip to content

fix(http): pass mypy --strict in the retry handler and pipeline and fix the bugs it shows - #810

Open
Max Azatian (HardMax71) wants to merge 3 commits into
microsoft:mainfrom
HardMax71:fix/strict-typing-retry-handler-pipeline
Open

Max Azatian (HardMax71) wants to merge 3 commits into
microsoft:mainfrom
HardMax71:fix/strict-typing-retry-handler-pipeline

Conversation

@HardMax71

@HardMax71 Max Azatian (HardMax71) commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Eighth item in #722. The retry handler and the middleware pipeline now pass mypy --strict, and errors in kiota_http go from 88 to 33 (mypy 2.4.0). Typing BaseMiddleware.send also clears untyped calls in the other handlers.

Related Issue

Part of #722.

Demo

Not needed for this change.

Notes

Adding the types showed seven bugs, each fixed with a test. MiddlewarePipeline with no middleware raised KeyError on every request (L42), and a middleware span with no parent span started a new trace instead of using the current one (L81). RetryHandler shared one default option between handlers (L45), never ended the span of a retried attempt (L91), crashed in get_delay_time without a response (L185) and failed the request on a Retry-After that is neither seconds nor a date (L201). RedirectHandler built a redirect history for response.history (L96), but httpx's AsyncClient sets that field itself after the transport returns, so the list never reached callers. Now the list stays local for increment.

Testing Instructions

  • mypy kiota_http passes in packages/http/httpx, and mypy --strict kiota_http shows nothing in middleware.py, retry_handler.py or async_kiota_transport.py, with 33 errors overall instead of 88.
  • yapf -dr kiota_http, pylint and pytest pass.
  • The new tests fail on main, except the one for increment overrides.

…ix the bugs it shows

Type MiddlewarePipeline, BaseMiddleware and RetryHandler. This also clears the two errors in AsyncKiotaTransport that came from the untyped pipeline. Part of microsoft#722.

Bugs found on the way, each with a test:

- MiddlewarePipeline with no middleware deleted a `request_options` header that is never set, so every request raised KeyError. It now drops the request options from `request.extensions`, like BaseMiddleware does.
- A middleware span with no parent span got a context with no span in it, so it started a new trace. It now uses the current context, as the docstring says.
- RetryHandler never ended the span of an attempt it retried. It now ends it before the retry.
- RetryHandler() shared one default RetryHandlerOption between all handlers. Each handler now gets its own.
- get_delay_time(retry_count) with the default response=None raised AttributeError. It now uses the backoff.
- A Retry-After value that is neither seconds nor an HTTP date raised ValueError and failed the request. It now falls back to the backoff.
- RedirectHandler put the redirect requests in response.history, but httpx keeps the earlier responses there. It now stores the responses.
@HardMax71
Max Azatian (HardMax71) requested a review from a team as a code owner October 16, 2026 16:40
Copilot AI balanced review requested due to automatic review settings October 16, 2026 16:40

This comment was marked as off-topic.

@HardMax71

Copy link
Copy Markdown
Contributor Author

hehe, first PR with 7 bugs detected (and fixed). If you need repros for each bug, I'm ready to provide them

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused changes have regression coverage and no identified blocking issues; tests were not independently executed.

0 open findings

🧠 Review effort: Balanced

Comment thread packages/http/httpx/kiota_http/middleware/redirect_handler.py Outdated
…andler

httpx's AsyncClient sets response.history itself after the transport returns, so the list RedirectHandler built never reached callers. A redirect counter, like the one in the C# handler, now drives the span name, the redirect count attribute and the error message.
Copilot AI balanced review requested due to automatic review settings October 16, 2026 19:51

This comment was marked as off-topic.

@baywet Vincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for making the changes!

@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Oct 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Redirect handling bypasses existing increment overrides, breaking subclass redirect policies.

1 open issue

Review effort: Balanced

Comment thread packages/http/httpx/kiota_http/middleware/redirect_handler.py Outdated
4127807 stopped calling the public increment method, so a subclass override that returns False no longer stopped a redirect. The loop is back to main's shape, with the request list kept local and never assigned to response.history.
Copilot AI balanced review requested due to automatic review settings October 19, 2026 15:33

This comment was marked as off-topic.

@sonarqubecloud

Copy link
Copy Markdown

@HardMax71

Copy link
Copy Markdown
Contributor Author

Vincent Biret (@baywet) fixes applied, ready for re-review (8cdbee3 brings back the increment call Copilot flagged, since the last push dropped your approval).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

Static review found no blocking issues in the focused changes and regression coverage; tests were not executed.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

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

Labels

None yet

Projects

Status: In Progress 🚧

Development

Successfully merging this pull request may close these issues.

3 participants