Closed dineshtrivedi closed 3 years ago
I wanted to create the issue and add a PR, but work has been very busy. Maybe I can get to this over the weekend.
Hmm, you might be right that this doesn't work as expected.
I think it'd make sense for anything that's Optional
(or Union[X, None]
) to set allow_null=True
. If there's a no default value, it should be required=False
, otherwise required=True
. However, changing this unfortunately will be a BC break.
We can probably set default
as well, but I've to check whether that works properly with updates and won't unintentionally overwrite unsupplied fields with the default value.
Thank you @oxan, looking forward to this. :)
Thank you @oxan I really appreciate it. I am sorry for not helping with the work, I just haven't managed to put time aside for it.
I am experiencing some behaviors that seem to be weird for me. The case is mainly when I use Optional and defaults values in my dataclass and pass it in the class Meta. I started to suspect when I used the Serializer using DataclassSerializer in swagger.
Here is a code example with comments:
You can read the FIXME comments, but the summary of the rules that seems to be right for me are these:
I have a project running the example above with swagger, you can check here in case that helps - https://github.com/dineshtrivedi/django-architecture/tree/drf-dataclass-issue-1
What do you think? Does it make sense what I am proposing?