Skip to content

fix(openapi): keep blank values in parse_qs (refs #4056)#4076

Open
MukundaKatta wants to merge 1 commit intoPrefectHQ:mainfrom
MukundaKatta:fix/parse-qs-keep-blank-values
Open

fix(openapi): keep blank values in parse_qs (refs #4056)#4076
MukundaKatta wants to merge 1 commit intoPrefectHQ:mainfrom
MukundaKatta:fix/parse-qs-keep-blank-values

Conversation

@MukundaKatta
Copy link
Copy Markdown
Contributor

@MukundaKatta MukundaKatta commented Apr 28, 2026

Problem

HeadlessOAuth.callback_handler parses OAuth callback query strings with parse_qs(parsed.query) without keep_blank_values=True.

That drops explicitly empty values, so ?code=abc&state= is treated the same as a missing state, and ?error=invalid_request&error_description= falls back to Unknown error instead of preserving the provider's empty description.

MRE

from urllib.parse import parse_qs

assert parse_qs("code=abc&state=").get("state") is None
assert parse_qs("code=abc&state=", keep_blank_values=True)["state"] == [""]

Fix

Add keep_blank_values=True to the remaining parse_qs call in src/fastmcp/utilities/tests.py.

Tests

Added focused coverage for:

  • blank state round-tripping as ""
  • missing state still returning None
  • blank error_description staying blank instead of using the fallback

Refs #4056. This PR is intentionally scoped to the remaining HeadlessOAuth.callback_handler call site; #4069 handled the template parser path.

The HeadlessOAuth callback handler in src/fastmcp/utilities/tests.py
called parse_qs() without keep_blank_values=True, so an explicitly-empty
query parameter (e.g. ?state= or ?error_description=) was silently
dropped. Real OAuth providers can emit empty values, and downstream code
uses .get("state", [None])[0] to distinguish "not present" (None) from
"present but empty" (""). Without the flag, both cases collapsed to None.

This is the same defect class that PR PrefectHQ#4069 fixed in
src/fastmcp/resources/template.py; this commit applies the same fix to
the remaining parse_qs call site so behavior is consistent across the
code base.

Adds three regression tests in tests/utilities/test_tests.py covering
blank state, missing state, and blank error_description.
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@marvin-context-protocol marvin-context-protocol Bot added bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. auth Related to authentication (Bearer, JWT, OAuth, WorkOS) for client or server. too-long Excessively verbose or unedited LLM output. Condense before triage. labels Apr 28, 2026
@marvin-context-protocol
Copy link
Copy Markdown
Contributor

Thanks for the report. This issue goes beyond what our contributor guidelines ask for — we just need a short problem description and an MRE. Please see our contributing guidelines and condense this issue. We'll triage it once it's trimmed down.

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

Labels

auth Related to authentication (Bearer, JWT, OAuth, WorkOS) for client or server. bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. too-long Excessively verbose or unedited LLM output. Condense before triage.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant