Questions tagged [marshmallow-dataclass]

8 questions
2
votes
1 answer

Custom type serialization inside a data class

I have recently discovered python dataclasses, and I am trying to implement a dataclass, which has some 3rd party library type as a field. This member has its own serialisation methods, and special handling should be possible to define in…
1
vote
0 answers

TypeError when creating a marshmallow schema from dataclass inherited from generic class

I'm trying to create a marshmallow schema from dataclass which is inherited from generic type: users_schema = marshmallow_dataclass.class_schema(Users)() This is my code: from dataclasses import dataclass from typing import Generic, List,…
1
vote
2 answers

marshmallow dataclass serialization: dump field with different name as load using 'data_key' and 'attribute'

I'm having trouble using the attribute field of marshmallow dataclasses (v3.x). My problem: I get the input keys for schema.load as dict with non-python-valid names e.g. "external.id" and I want the output keys with schema.dump to be different e.g.…
0
votes
1 answer

Dataclass with Marshmallow Schema failing on schema load method

I'm working with a dataclass which follows a marshmallow Schema, where this is the setup: from marshmallow_dataclass import dataclass import datetime from typing import ClassVar, Type import marshmallow class BaseClass: Schema:…
0
votes
1 answer

Set Required=True based on a condition in marshmallow

I was wondering whether there is a way in marshmallow to have a field to be required depending on another value. Eg: { 'name':'Tom' } { 'name':'Arthur', 'job':'teacher' } I'd like to know if there is a way to make the field job required if…
0
votes
1 answer

marshmallow NewType can not be turned into a dataclass, python 3.10

I'm in the process of upgrading to python 3.10 and in that context I thought it would be nice to also upgrade packages used. Right now, the problem is with the marshmallow packages and at this point I can't even run their example code for NewType…
myrtille
  • 105
  • 3
0
votes
1 answer

Can you have a conditional encoding dependent on whether a date time value is None?

Is it possible for the approver_time value to be encoded/ decoded only when the date time value is not set to None? @dataclass_json(letter_case=LetterCase.CAMEL) @dataclasses.dataclass class A: approver_time: datetime.datetime =…
kev0h1
  • 25
  • 5
0
votes
1 answer

How to prevent Marshmallow from partial dumping?

I have next data class and schema: @dataclass class Period: id: int year: int month: EMonth closed_at: Optional[datetime] PeriodSchema = marshmallow_dataclass.class_schema(Period) The problem is Marshmallow allows a partial dumping…
Denis Sologub
  • 7,277
  • 11
  • 56
  • 123