`required: True` set on a nullable field which is included in combined_unique
Checklist
- [ ] Raised initially as discussion #...
- [x] This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
- [x] I have reduced the issue to the simplest possible case.
My Model:
class Model:
f1 = models.CharField()
f2 = models.CharField()
f3 = models.CharField(null=True, blank=True)
class Meta:
unique_together = ('f1', 'f2', 'f3')
This definition implies f1 and f2 should combinedly be unique when f3 is null, but ModelSerializer.get_uniqueness_extra_kwargs marks all fields in unique_together as required: True
Suggestion:
Ignore marking the fields as required: True when there are more than 2 fields in unique_together
Temporary fix
adding default=None on f3 currently bypasses adding required: True on it
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Should be fixed
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Valid bug
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Closing valid tickets is not solving them
that stale bot is annoying but it is also sending me notification for looking into so called stalled issues :D
It is already a deprecated feature in django and DRF still do not support it properly. but if you can send an improvement request it would great
For this ticket, I don’t remember why I found it and subscribed to it.
One project had an issue that was solved by django adding models.UniqueConstraint with condition parameter, so it’s not that.
Maybe this one is stale and won’t fix!