Model unique_for_month changes ability to partially update ModelSerializer

Author: jambonroseCreated Nov 28, 2018Updated Sep 12, 2026

If I have a model and a ModelSerializer, then I can partially update model instances using the serializer. For instance, given a Post model, and a basic PostSerializer, shown below, I can update a Post instance using the serializer.

python
class Post(Model):
    title = CharField(max_length=63)
    slug = SlugField(max_length=63)
    pub_date = DateField(default=date.today)
python
class PostSerializer(ModelSerializer):
    class Meta:
        model = Post
        fields = "__all__"

I use the code below to achieve the actual update.

python
post = Post.objects.create(title="first", slug="slug")
s_post = PostSerializer(instance=post, data={"title": "second"}, partial=True)
if s_post.is_valid():
    s_post.save()  # updates the title from first->second

The problem is that if I add a unique_for_month constraint on the SlugField, I lose the ability to use the code above.

python
class Post(Model):
    title = CharField(max_length=63)
    slug = SlugField(max_length=63, unique_for_month="pub_date")
    pub_date = DateField(default=date.today)

If I run the update code with the PostSerializer as shown above, then the serializer will have the following errors:

python
{
    'slug': [
        ErrorDetail(
            string='This field is required.',
            code='required'
        ),
    ],
    'pub_date': [
        ErrorDetail(
            string='This field is required.',
            code='required'
        )
    ],
}

I believe this is a bug, but apologize if I've misunderstood.

Source: encode/django-rest-framework