max_length validation is not wroking with Modelserializer #9489
-
I created a model have a field as charField and has max_length then i created a model serailzer for that model by the serializer is not validating the field with max_length class MyModel(models.Model): class MyModelSerializer(ModelSerializer): when I send a post request with name as 256 chars it is throwing 500 it should throw 400 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi Anshulgoplus, Thank you for raising this issue. The problem you described involves the validation of the maximum length of a Issue Analysis Proposed Solution from rest_framework import serializers
class MyModelSerializer(serializers.ModelSerializer):
name = serializers.CharField(max_length=255)
class Meta:
model = MyModel
fields = '__all__' Explanation Conclusion Thank you again for your contribution! Best regards, |
Beta Was this translation helpful? Give feedback.
-
@Anshulgoplus I can't seem to replicate this issue with the latest version of djangorestframework and without explicitly defining the name field in the serializer as suggested above, I got the following validation error with status code 400.
|
Beta Was this translation helpful? Give feedback.
-
Hi @Anshulgoplus, Thank you for your prompt feedback. It's great to hear that you couldn't replicate the issue with the latest version of Django REST Framework and that the validation error is being correctly handled with a status code 400. |
Beta Was this translation helpful? Give feedback.
@Anshulgoplus I can't seem to replicate this issue with the latest version of djangorestframework and without explicitly defining the name field in the serializer as suggested above, I got the following validation error with status code 400.