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 by default:
PeriodSchema().dumps(None) # '{"closed_at": null}'
I need to the Marshmallow dumped my entity or returned {} or '', or null, in short a some default value.
How to fix a default behaviour?
I think this is not the best solution but it helped me as a hot fix:
In short, we just override used methods and check for empty dictionaries and strings.