Django EmbeddedModelField saying “This field may not be blank” when doing PUT request despite field having “blank=True”

Django EmbeddedModelField saying “This field may not be blank” when doing PUT request despite field having “blank=True”

I'm creating a Django application with django-rest-framework and using djongo to connect to MongoDB. I have nested models as such:

I'm creating a Django application with django-rest-framework and using djongo to connect to MongoDB. I have nested models as such:

class Group(models.Model):
    users = models.ArrayModelField(
        model_container=User
    )

class User(models.Model): number = models.IntegerField( default=None, null=True )

song = models.EmbeddedModelField(
    model_container=Song,
    null=True,
    blank=True
)

class Meta:
    abstract = True

class Song(models.Model): mp3_file = models.URLField( default=None, blank=True, null=True )

comments = models.CharField(
    max_length=250,
    default='',
    blank=True
)

class Meta:
    abstract = True

When a Group is created, the Users and the Songs are created without any problems. For example, when created, the Group may look like:

{
    "name": "Sample",
    "users: [
        {
            "number": null,
            "song": {
                "mp3_file": null,
                "comments": ""
            }
        }
    ]
}

This all works fine. However, if I try to do a PUT request and don't change the value of "number", "mp3_file", or "comments", I will get the following error message:

"user": [
    {
        "number": [
            "This field may not be null."
        ],
        "song": {
            "mp3_file": [
                "This field may not be null."
            ],
            "comments": [
                "This field may not be blank."
            ]
        }
    }
]

Any thoughts on how to fix this error? I am just using a generic RetrieveUpdateDestroyAPIView as the view for this endpoint.

edit: I have also tried recreating all migrations as well as dropping the table and recreating it, and neither of those approaches helped.

edit: Here is the view:

class GroupDetail(generics.RetrieveUpdateDestroyAPIView):
    serializer_class = GroupSerializer
    queryset = Group.objects.all()
    lookup_field = 'group_name'
    lookup_url_kwarg = 'group_name'

And the serializers:

class GroupSerializer(serializers.HyperlinkedModelSerializer):
    users = UserSerializer(many=True)

def update(self, instance, validated_data):
    if validated_data.get('group_name', None) is not None:
        instance.__setattr__('group_name', validated_data.get('group_name'))

    instance.save()

    return instance

class Meta:
    model = Group
    fields = (
        'group_name',
        'users'
    )

class UserSerializer(serializers.Serializer): number = serializers.IntegerField() song = SongSerializer()

class SongSerializer(serializers.Serializer): mp3_file = serializers.URLField() comments = serializers.CharField( max_length=250 )

But part of the issue is that the serializers are never even being reached since the data is validating incorrectly.

django mongodb

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

MongoDB Database and java applications

Enroll for free demo to acquire the best knowledge on the schema-less database from live industry experts through MongoDB training

Main Pros and Cons of Django As A Web Framework for Python Developers

India's best Institute for Django Online Training Course & Certification. Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.

Python Django Tutorial | Django Course

🔥Intellipaat Django course: https://intellipaat.com/python-django-training/ 👉This Python Django tutorial will help you learn what is django web development &...

Which is the Best MongoDB GUI?

Our MongoDB Online Training provide you to learn about MongoDB strategies with realty. Our MongoDB Online Training also includes live sessions, live Projects, and much

Improve the MongoDB Aggregation Framework

Our MongoDB Online Training provide you to learn about MongoDB strategies with realty. Our MongoDB Online Training also includes live sessions, live Projects, and much