Commit 54af90d
committed
fix(parsing): drop TextFormatT parameterization in parse_response (#3084)
Closes #3084.
parse_response() called construct_type_unchecked with three types
parameterized by a free TypeVar (ParsedResponseOutputText[TextFormatT],
ParsedResponseOutputMessage[TextFormatT], ParsedResponse[TextFormatT]).
Pydantic cannot resolve a free TypeVar, so model_rebuild(raise_errors=False)
returns False on every invocation. MockCoreSchema._built_memo only caches
the rebuilt schema when model_rebuild succeeds; when it fails, the cache
is never set and a new Rust-backed SchemaValidator/SchemaSerializer is
allocated on every parse_response() call.
Result: heavy pydantic-core objects leak without bound whenever
AsyncResponses.parse() is called in a long-lived process. This is
observable as a flame-graph spike (see #3084 for the screenshot).
Fix (per issue author's diagnosis): drop the [TextFormatT]
parameterization at the runtime type_= argument. At runtime Python's
generics are erased anyway — the constructed object's type is
identical either way. Only the pydantic schema rebuild path differs:
with the non-parameterized generic, model_rebuild succeeds and the
schema is cached in _built_memo.
Tests: all 5 existing tests in tests/lib/responses/test_responses.py
continue to pass (verified locally). No behavior change for callers.
Signed-off-by: Mukunda Katta <mukunda.vjcs6@gmail.com>1 parent 750354e commit 54af90d
1 file changed
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
| |||
78 | 82 | | |
79 | 83 | | |
80 | 84 | | |
81 | | - | |
| 85 | + | |
| 86 | + | |
82 | 87 | | |
83 | 88 | | |
84 | 89 | | |
| |||
130 | 135 | | |
131 | 136 | | |
132 | 137 | | |
133 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
134 | 142 | | |
135 | 143 | | |
136 | 144 | | |
| |||
0 commit comments