django-rest-framework icon indicating copy to clipboard operation
django-rest-framework copied to clipboard

`required: True` set on a nullable field which is included in combined_unique

Open tiholic opened this issue 4 years ago • 8 comments

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

tiholic avatar Dec 04 '21 08:12 tiholic

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.

stale[bot] avatar Apr 17 '22 04:04 stale[bot]

Should be fixed

merwok avatar Apr 18 '22 16:04 merwok

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.

stale[bot] avatar Jun 19 '22 15:06 stale[bot]

Valid bug

merwok avatar Jun 20 '22 14:06 merwok

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.

stale[bot] avatar Nov 23 '22 07:11 stale[bot]

Closing valid tickets is not solving them

merwok avatar Nov 23 '22 16:11 merwok

that stale bot is annoying but it is also sending me notification for looking into so called stalled issues :D

auvipy avatar Nov 24 '22 05:11 auvipy

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

auvipy avatar Nov 24 '22 05:11 auvipy

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!

merwok avatar Nov 24 '22 16:11 merwok