Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ideas to a better way to instace of the dataclass instantiate_data_dictionaries #12

Closed
Provoo opened this issue Feb 13, 2020 · 2 comments

Comments

@Provoo
Copy link

Provoo commented Feb 13, 2020

Hi I red the coment below in instantiate_data_dictionaries:

# I'm not sure this is actually the best way to deserialize into nested dataclasses. The cleanest way seems to
        # be overriding to_internal_value(), but the top-level serializer must return a dictionary from that method. We
        # could split nested dataclasses off into a separate DataclassField (which could in general clean-up the code a
        # bit), but that breaks specifying nested serializers using a single class. Let's use this ugly hack until I can
        # think of something better.

First i want to congratulate you, with dataclasses django and python are becoming much better a robust to deploy productions services, I'm also front end developer and is amazing how with typescript and angular you can prevent a lot of bugs with de interfaces, I have been looking away to replacate that in backend, i tryed TypedDict, but my code steel been very dificult to debug, so when I started to use dataclasses and your library, the enpoint works like magic.

So I was wondering or I don't understand why you dont instance the main Dataclass instead of creating a Dict, if you want I can try to create this improvement.

Thanks again for your amazing work!

@Provoo Provoo changed the title Ideas to better way to instace of the dataclass instantiate_data_dictionaries Ideas to a better way to instace of the dataclass instantiate_data_dictionaries Feb 13, 2020
@oxan
Copy link
Owner

oxan commented Feb 22, 2020

Thanks for your kind words!

I'm not exactly sure what you mean though. This is just an implementation detail, for the enduser this is completely opaque and they already get an instance of the main dataclass.

The problem hinted at here is that the location where that dataclass is instantiated. Ideally, I'd want to do that in to_internal_value(), so that nesting automatically works. However, DRF doesn't allow us to do that on the outermost serializer, so we have to do it somewhere else. I don't see what your suggestion to change that is.

@oxan
Copy link
Owner

oxan commented Feb 22, 2020

encode/django-rest-framework#6053 and encode/django-rest-framework#6365 make me think this might not be intentional on DRF's side, so maybe I should look into why it doesn't work.

@oxan oxan closed this as completed in a4cc1c6 Apr 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants