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

Add .load_to_dict method to base schema #213

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dairiki
Copy link
Collaborator

@dairiki dairiki commented Sep 23, 2022

Following up on this suggestion made in a comment on #169 (see also #210), this provides a new schema method, .load_to_mapping, that essentially does a raw marshmallow.Schema.load without converting any of the deserialized values (either top-level or nested) to dataclasses. The main point of this is to allow for deserializing partial data (with partial=True).

This PR is provided for discussion, as to:

  • whether it's worthwhile
  • whether there's a better name for the new method
  • whether there's a better way to implement the new method
  • ...

This essentially does a raw marshmallow.Schema.load without
converting any values to dataclasses.  The main point is
to allow doing loads with `partial=True`.
@lovasoa
Copy link
Owner

lovasoa commented Sep 24, 2022

I'm ok with that ! Maybe load_to_dict is clearer than load_to_mapping ? Doesn't it always return a dict ?

@dairiki
Copy link
Collaborator Author

dairiki commented Sep 24, 2022

I'm ok with that ! Maybe load_to_dict is clearer than load_to_mapping ? Doesn't it always return a dict ?

Yes, that's probably better.

After some digging through the marshmallow source code it appears to always return dict (or OrderedDict) (or a list of those if many is set). I will rename it.

@dairiki dairiki changed the title Add .load_to_mapping method to base schema Add .load_to_dict method to base schema Sep 27, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants