GithubHelp home page GithubHelp logo

Comments (3)

JWCook avatar JWCook commented on June 10, 2024

Okay, I think I understand what's happening:

  • cattrs: JsonConverter now uses the new function configure_union_passthrough() here to register a Union type containing all JSON primitive types.
    • This is to handle results from a JSON deserializer that produces values with these types. Each value will be structured using its individual type (say, a float) instead of treating the Union itself as a special type.
  • requests-cache: CachedResponse._decoded_content is annotated with DecodedContent, a Union type alias for decoded content from a response with either application/json or text/*.
  • requests-cache: the converter used by CattrStage registers a structure hook for DecodedContent.
    • This is handled specially to allow being unstructured into a fully human-readable JSON (or YAML, etc.) file instead of a binary blob, mainly for use with the Filesystem, MongoDB, and DynamoDB backends.
  • cattrs: The "union passthrough" strategy kicks in before this hook has a chance to run.
    • It handles JSON primitive types, but not JSON document root types (dict and list).
    • The diff between the registered Union and the DecodedContent Union becomes Union[List, Dict].
    • It treats this as a "spillover type" here, and looks for a converter for Union[List, Dict], which doesn't exist, raising an error.

This may be more of a problem with how I'm using cattrs; maybe modifying/extending the pre-configured converters isn't an intended use case? The docs for the preconf module do say they're "specifically adjusted for particular serialization libraries" (in this case json/ujson), i.e. they expect output directly from one of those libraries.

This did work prior to 23.2, though.

from requests-cache.

JWCook avatar JWCook commented on June 10, 2024

So the workaround I mentioned above turns out to be a reasonable solution for this.

I think a better long-term solution would be to implement support for RFC 7159 (#868), and handle the logic for the decode_content option after the cattrs converter runs, instead of as part of the converter.

from requests-cache.

JWCook avatar JWCook commented on June 10, 2024

Fixed in main, and patched in v1.1.1.

from requests-cache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.