Repository navigation
fix(proxy): strip every TypedDict qualifier before numeric form-field detection - #39780
Conversation
… detection _numeric_form_type only peeled a single ReadOnly layer, so a field still wrapped in Required/NotRequired was read as non-numeric and dropped from the mapping. Which qualifiers survive get_type_hints varies by interpreter version and by include_extras, so on Python 3.10 NotRequired[ReadOnly[int]] reached the check intact and the field was silently skipped, which is what turns the mapped test red on the 3.10 leg only. Peel Required/NotRequired/ReadOnly/Annotated in any order and nesting instead. The one production caller feeds a schema with no qualifiers, so the resulting mapping is unchanged on every interpreter in the matrix, but a field written the house-convention way stops being dropped.
Greptile SummaryThe PR makes numeric multipart form-field detection recursively remove supported TypedDict and annotation qualifiers before identifying
Confidence Score: 5/5The PR appears safe to merge with no actionable failures established in the current request path. The recursive unwrapping preserves existing scalar and union handling, and the expanded tests cover the qualifier combinations introduced by this fix.
|
| Filename | Overview |
|---|---|
| litellm/proxy/common_utils/http_parsing_utils.py | Recursively unwraps recognized annotation qualifiers before numeric form-field type detection. |
| tests/test_litellm/proxy/common_utils/test_http_parsing_utils.py | Extends numeric-field tests across nested qualifier orders and preserved annotation extras. |
| tests/code_coverage_tests/recursive_detector.py | Documents and exempts the bounded qualifier recursion from generic recursion checks. |
Reviews (2): Last reviewed commit: "ci: allowlist the bounded _unqualified q..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…itellm_/goofy-bohr-6cd011
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit cd113c3. Configure here.
77e27b1
into
litellm_internal_staging
TLDR
Problem this solves:
Required/NotRequiredwas silently droppedHow it solves it:
ReadOnlyinclude_extras=TrueUser Flow
Before: every PR opened against
litellm_internal_stagingshows theproxy-infra / Run tests (Python 3.10)check red on a test its branch never touched, and the staging branch's own run is red the same waylitellm_internal_stagingat https://github.com/BerriAI/litellm/comparehttps://github.com/BerriAI/litellm/pull/{number}/checksand seeproxy-infra / Run tests (Python 3.10)fail while the 3.11 through 3.14 legs of the same shard passtests/test_litellm/proxy/common_utils/test_http_parsing_utils.py::TestNumericFormFields::test_qualifiers_and_optionality_are_unwrappedfailing withassert {'read_only'} == {'read_only', 'not_required', 'required', ...}, in a file their branch never changedAfter: the same PR's
proxy-infra / Run tests (Python 3.10)check passes alongside the other legs, and the staging branch's own run is greenlitellm_internal_stagingat https://github.com/BerriAI/litellm/comparehttps://github.com/BerriAI/litellm/pull/{number}/checksand seeproxy-infra / Run tests (Python 3.10)green with the 3.11 through 3.14 legsRelevant issues
Linear ticket
Resolves LIT-6947
Pre-Submission checklist
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
The check this PR exists for
59d42d36e6:proxy-infra / Run tests (Python 3.10)fails onTestNumericFormFields::test_qualifiers_and_optionality_are_unwrappedwhile the 3.11 through 3.14 legs of the same shard pass: https://github.com/BerriAI/litellm/actions/runs/33933426456/job/101216565174cd113c3a2e: all five legs pass, the 3.10 one included: https://github.com/BerriAI/litellm/actions/runs/33935529515/job/101222597269What the peel changes for a gateway user
Both legs run on Python 3.10 (the only leg that reproduces this) with a proxy booted with
--num_workers 2on a random free port against real providers, and differ only in the commit the proxy was booted from: the Before leg is the merge base59d42d36e6, the After leg is this PR's tipcd113c3a2e. Shared setup:square1024.pngis a 1024x1024 PNG. Responses are summarised as their status code plus how many images came back, since eachb64_jsonis over a megabyteThe shipped
ImageEditRequestParamswritesnas a bareint | None, which never trips the bug, so case 2 below writes that one field the way the repo's TypedDict convention asks for (n: NotRequired[ReadOnly[int | None]]) to show what the fix buys. That schema line is a local QA change only, applied identically on both legs, and is not part of this PRBefore (59d42d3)
Case 1: shipped schema,
n=2sent as a form field-F "model=gemini-image"and-F "n=1":Case 2:
nwritten the house-convention wayn=2n=1: stillHTTP 200,images: 1(Gemini accepts a text count, so the symptom never shows there)After (cd113c3)
Case 1: shipped schema,
n=2sent as a form fieldCase 2:
nwritten the house-convention wayn=2n=1:HTTP 200,images: 1Observations from the run:
Type
🐛 Bug Fix
Caveats (if any)
Low
nis a bareint | None, so today's gateway forwards it as a number on every Python already; the peel guards theNotRequired[ReadOnly[...]]shape the TypedDict convention produces. Rewriting the shipped schema here would be scope creep on a CI fix, so it stays<shard> / Run testslegs are), so the red blocked PRs by being visible rather than through the merge gate. Left alone: which legs gate merges is a ruleset decision, not this PR's_unqualifiedis allowlisted intests/code_coverage_tests/recursive_detector.pylike the sibling_flatten_form_field: its recursion is bounded by the qualifier depth of a static annotation, and a depth cap would only add a branch no schema can reachproxy_store_model_in_db_testsis red at this tip ontest_chat_completion_bad_model_with_spend_logs(assert '' == 'non-existent-model'), the same staging-wide failure the branch shows on its own; test(store_model_in_db): assert the 400 contract in the unknown-model spend log test #39842 fixes that test under LIT-6949, and the job is not a ruleset-required contextFinal Attestation
The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
cd113c3 passes /live-pr-risk