long2ice / fastapi-cache

fastapi-cache is a tool to cache fastapi response and function result, with backends support redis and memcached.
https://github.com/long2ice/fastapi-cache
Apache License 2.0
1.37k stars 167 forks source link

Coder.decode_as_type version history #460

Open vicchi opened 2 weeks ago

vicchi commented 2 weeks ago

@long2ice As part of #459 I've been looking at the revision history for the Coder.decode_as_type method. Support for decoding JSON to a custom return type was added in commit f78a599b by @mjpieters in May 2023 but then removed again in commit 19c4d027 by John Lyu (whose GitHub account doesn't seem to exist anymore).

Was this intentional?

As it stands right now, the current JsonCoder unit tests will never pass in their current form for a dataclass or a Pydantic model because decoding to a custom return type is no longer implemented and the type_ parameter is never used.

Unless I'm missing something which is entirely possible. For now I'll comment out those specific test values and focus on the failing test for the @cache decorator but it would be good to know the history behind this.

vicchi commented 2 weeks ago

The same applies to decoding back to a tuple as the closest JSON analogue is an array, so both a Python list and a tuple will always encode to an array and decode back to a list.