fix: isolate type decoders from shared signature annotation state#4639
fix: isolate type decoders from shared signature annotation state#4639maksimzayats wants to merge 1 commit intolitestar-org:mainfrom
Conversation
sobolevn
left a comment
There was a problem hiding this comment.
I would categorize this as a tricky optimization instead of just a bug. Current behavior looks more correct to me. However, we also have to measure the perf impact of this change.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4639 +/- ##
==========================================
- Coverage 97.87% 97.87% -0.01%
==========================================
Files 292 292
Lines 15077 15067 -10
Branches 1703 1701 -2
==========================================
- Hits 14757 14747 -10
Misses 184 184
Partials 136 136 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @sobolevn ! Hmm, the old behavior looks quite strange to me tbh... and it looks like more a bug, but I'd love to hear other maintainers opinion on this |
|
Context: jcrist/msgspec#497 and jcrist/msgspec#483 |
|
Agree with @sobolevn. Yes, it's a bit iffy to store things globally like this, but it's an optimisation we deemed worth it, as the lookup process is quite expensive. If you want to remove this, I'd need comprehensive benchmarks to show there's no negative impact on performance |
Description
This removes the shared
_decodermutation from signature parsing.Previously,
SignatureModel.create()could attach a decoder directly to the annotated type, which made decoder behavior process-global. That meant one handler, app, or DI provider could accidentally affect another if they used the same annotation class.Now, signature parsing no longer mutates user-defined or stdlib classes. Request parsing stays scoped to the current handler or provider through the existing
default_deserializer(type_decoders=...)path.Old behavior:
New behavior:
📚 Documentation preview 📚: https://litestar-org.github.io/litestar-docs-preview/4639