Coder Social home page Coder Social logo

to_dict/to_json not working with postponed annotations for Generic dataclass, if typed class is defined in different module about mashumaro HOT 6 CLOSED

AntonOvsyannikov avatar AntonOvsyannikov commented on June 19, 2024
to_dict/to_json not working with postponed annotations for Generic dataclass, if typed class is defined in different module

from mashumaro.

Comments (6)

Fatal1ty avatar Fatal1ty commented on June 19, 2024

Hi @AntonOvsyannikov

Thank you for the illustrative example. In my production code I don't use postponed annotations, that's why this problem hadn't been discovered before you did :)

This bug seems to be caused by explicit passing globals of the Baz's module to typing.get_type_hints here. Without it typing.get_type_hints would get globals of the base class, in our example Foo, here. At first glance the fix is straightforward, but I have to think about this more carefully just so as not to break something else.

from mashumaro.

Fatal1ty avatar Fatal1ty commented on June 19, 2024

Hi @AntonOvsyannikov

I came to conclusion to remove explicit globals and locals passing to typing.get_type_hints that will definitely solve this issue. All the tests are passing and it seems not to break something. Anyway, it would be nice if you check this branch before going to release.

from mashumaro.

mishamsk avatar mishamsk commented on June 19, 2024

@Fatal1ty we are working with @AntonOvsyannikov on the same thing, so let me chime in here. I can confirm that the fix works for the sample code and probably in our real life code, however I stumbled on a new bug and can't fully test. See this #91

from mashumaro.

Fatal1ty avatar Fatal1ty commented on June 19, 2024

Merged and will be available in an upcoming release.

from mashumaro.

mishamsk avatar mishamsk commented on June 19, 2024

@Fatal1ty thanks a lot!

from mashumaro.

Fatal1ty avatar Fatal1ty commented on June 19, 2024

Fixed in 3.3.1.

from mashumaro.

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.