Skip to content

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

@tiholic

Description

@tiholic

Checklist

  • Raised initially as discussion #...
  • 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.)
  • 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions