Skip to content

Commit

Permalink
Bugfix: add missing max_length check on TagSerializer
Browse files Browse the repository at this point in the history
Issue: CORE-4S2

Progress on comses#377
  • Loading branch information
cpritcha committed Aug 1, 2018
1 parent f0a2482 commit b2ba5ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def save(self, **kwargs):


class TagSerializer(serializers.ModelSerializer):
name = serializers.CharField() # disable uniqueness check so TagListSerializer will validate properly
name = serializers.CharField(max_length=Tag._meta.get_field('name').max_length) # disable uniqueness check so TagListSerializer will validate properly

class Meta:
model = Tag
Expand Down
14 changes: 14 additions & 0 deletions django/core/tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.test import TestCase
from taggit.models import Tag

from core.serializers import TagSerializer


class TagSerializerTestCase(TestCase):
def test_name_max_length_check_respected(self):
too_long = Tag._meta.get_field('name').max_length + 1
name_too_long = TagSerializer(data={'name': 'a'*too_long})
self.assertFalse(name_too_long.is_valid())

valid_name = TagSerializer(data={'name': 'fishing'})
self.assertTrue(valid_name.is_valid())

0 comments on commit b2ba5ca

Please sign in to comment.