Fixed #22272 -- Fixed regression in DecimalField when using decimal_places=0.

Thanks to trac user merb for the report.
This commit is contained in:
Baptiste Mispelon 2014-03-14 17:20:31 +01:00
parent 666a2ad22f
commit 37f7f233f5
2 changed files with 12 additions and 2 deletions

View File

@ -1379,9 +1379,9 @@ class DecimalField(Field):
def deconstruct(self): def deconstruct(self):
name, path, args, kwargs = super(DecimalField, self).deconstruct() name, path, args, kwargs = super(DecimalField, self).deconstruct()
if self.max_digits: if self.max_digits is not None:
kwargs['max_digits'] = self.max_digits kwargs['max_digits'] = self.max_digits
if self.decimal_places: if self.decimal_places is not None:
kwargs['decimal_places'] = self.decimal_places kwargs['decimal_places'] = self.decimal_places
return name, path, args, kwargs return name, path, args, kwargs

View File

@ -110,6 +110,16 @@ class FieldDeconstructionTests(TestCase):
self.assertEqual(args, []) self.assertEqual(args, [])
self.assertEqual(kwargs, {"max_digits": 5, "decimal_places": 2}) self.assertEqual(kwargs, {"max_digits": 5, "decimal_places": 2})
def test_decimal_field_0_decimal_places(self):
"""
A DecimalField with decimal_places=0 shoudl work (#22272).
"""
field = models.DecimalField(max_digits=5, decimal_places=0)
name, path, args, kwargs = field.deconstruct()
self.assertEqual(path, "django.db.models.DecimalField")
self.assertEqual(args, [])
self.assertEqual(kwargs, {"max_digits": 5, "decimal_places": 0})
def test_email_field(self): def test_email_field(self):
field = models.EmailField() field = models.EmailField()
name, path, args, kwargs = field.deconstruct() name, path, args, kwargs = field.deconstruct()