So there's a change between v3.14.0 and v3.15.1 involving serializer fields
that are part of a UniqueConstraint, and this change isn't documented to my
knowledge. Consider the following example:
class Dummy(models.Model):
name = models.TextField(blank=True)
url = models.URLField()
class Meta:
constraints = [models.UniqueConstraint(fields=["url", "name"],
name="url_name_unique")]
class DummySerializer(serializers.ModelSerializer):
class Meta:
model = Dummy
fields = ("name", "url")
In DRF 3.14.0, creating a Dummy using a DummySerializer without specifying
a name will work (the name will be the empty string). But in DRF 3.15.1,
this will not work. You'll get the error 'This field is required.' for the
name field, and looking at the codebase, this seems to be due to changes to
`get_uniqueness_extra_args` in serializers.py, which make a field that is
part of a UniqueConstraint required by default.
To my knowledge, this change in behavior is not documented, so I thought
I'd bring it to people's attention.
Thanks!
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-rest-framework/4cb5aad0-d5e2-4500-b68c-d059e9fd17a5n%40googlegroups.com.