marshmallow_dataclass icon indicating copy to clipboard operation
marshmallow_dataclass copied to clipboard

Add .load_to_dict method to base schema

Open dairiki opened this issue 3 years ago • 2 comments

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
  • ...

dairiki avatar Sep 23 '22 23:09 dairiki

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

lovasoa avatar Sep 24 '22 10:09 lovasoa

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 avatar Sep 24 '22 19:09 dairiki