UniqueValidator don't respect model error_messages for relation #7778
-
When we have unique relation field (one to one for example) then UniqueValidator should respect error_messages from this field. But for now it always return default error message. # models
class FirstModel(models.Model):
pass
class SecondModel(models.Model):
relation_field = models.OneToOneField(
'FirstModel',
on_delete=models.CASCADE,
error_messages={
'unique': 'my message'
},
)
# serializer
class SecondModelSerializer(serializers.ModelSerializer):
class Meta:
model = SecondModel
fields = ('relation_field',)
# issue
FirstModel.objects.create()
SecondModel.objects.create(relation_field=1)
serializer = SecondModelSerializer(data={'relation_field': 1})
serializer.is_valid()
errors = serializer.errors Expected
Actual result
It's the same #2878, but for relation. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
These things are a lot easier to assess in free time if you make the effort to explain the issue fully. Having to dig up the history makes it a bit off putting. |
Beta Was this translation helpful? Give feedback.
Merged