Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #22199: Bad max_length deconstruction for FileField

  • Loading branch information...
commit cd7a2a077ed5dc4dd04e55d60e72fd15d71e928a 1 parent 28779ab
@andrewgodwin andrewgodwin authored
View
4 django/db/models/fields/files.py
@@ -270,9 +270,7 @@ def _check_primary_key(self):
def deconstruct(self):
name, path, args, kwargs = super(FileField, self).deconstruct()
- if kwargs.get("max_length", None) != 100:
- kwargs["max_length"] = 100
- else:
+ if kwargs.get("max_length", None) == 100:
del kwargs["max_length"]
kwargs['upload_to'] = self.upload_to
if self.storage is not default_storage:
View
19 tests/field_deconstruction/tests.py
@@ -128,6 +128,11 @@ def test_file_field(self):
self.assertEqual(path, "django.db.models.FileField")
self.assertEqual(args, [])
self.assertEqual(kwargs, {"upload_to": "foo/bar"})
+ field = models.FileField(upload_to="foo/bar", max_length=200)
+ name, path, args, kwargs = field.deconstruct()
+ self.assertEqual(path, "django.db.models.FileField")
+ self.assertEqual(args, [])
+ self.assertEqual(kwargs, {"upload_to": "foo/bar", "max_length": 200})
def test_file_path_field(self):
field = models.FilePathField(match=".*\.txt$")
@@ -135,11 +140,11 @@ def test_file_path_field(self):
self.assertEqual(path, "django.db.models.FilePathField")
self.assertEqual(args, [])
self.assertEqual(kwargs, {"match": ".*\.txt$"})
- field = models.FilePathField(recursive=True, allow_folders=True)
+ field = models.FilePathField(recursive=True, allow_folders=True, max_length=123)
name, path, args, kwargs = field.deconstruct()
self.assertEqual(path, "django.db.models.FilePathField")
self.assertEqual(args, [])
- self.assertEqual(kwargs, {"recursive": True, "allow_folders": True})
+ self.assertEqual(kwargs, {"recursive": True, "allow_folders": True, "max_length": 123})
def test_float_field(self):
field = models.FloatField()
@@ -276,11 +281,11 @@ def test_slug_field(self):
self.assertEqual(path, "django.db.models.SlugField")
self.assertEqual(args, [])
self.assertEqual(kwargs, {})
- field = models.SlugField(db_index=False)
+ field = models.SlugField(db_index=False, max_length=231)
name, path, args, kwargs = field.deconstruct()
self.assertEqual(path, "django.db.models.SlugField")
self.assertEqual(args, [])
- self.assertEqual(kwargs, {"db_index": False})
+ self.assertEqual(kwargs, {"db_index": False, "max_length": 231})
def test_small_integer_field(self):
field = models.SmallIntegerField()
@@ -302,3 +307,9 @@ def test_url_field(self):
self.assertEqual(path, "django.db.models.URLField")
self.assertEqual(args, [])
self.assertEqual(kwargs, {})
+ field = models.URLField(max_length=231)
+ name, path, args, kwargs = field.deconstruct()
+ self.assertEqual(path, "django.db.models.URLField")
+ self.assertEqual(args, [])
+ self.assertEqual(kwargs, {"max_length": 231})
+
Please sign in to comment.
Something went wrong with that request. Please try again.