Commits

Waldemar Kornewald  committed c1f3e6f

fix for Decimal "-0.0"

  • Participants
  • Parent commits b8232d0

Comments (0)

Files changed (2)

     def value_to_db_decimal(self, value, max_digits, decimal_places):
         if value is None:
             return None
-        sign = value < 0 and u'-' or u''
-        if sign: 
+
+        if value.is_signed():
+            sign = u'-'
             value = abs(value)
-        if max_digits is None: 
+        else:
+            sign = u''
+
+        if max_digits is None:
             max_digits = self.DEFAULT_MAX_DIGITS
 
         if decimal_places is None:

File tests/decimals.py

 from .testmodels import DecimalModel
 from django.test import TestCase
 
-from decimal import Decimal
+from decimal import Decimal, InvalidOperation
 D = Decimal
 
 class DecimalTest(TestCase):
         rows = DecimalModel.objects.all().order_by('decimal')
         values = list(d.decimal for d in rows)
         self.assertEquals(values, sorted(values))
+
+    def test_sign_extend(self):
+        DecimalModel(decimal=D('-0.0')).save()
+
+        try:
+            # if we've written a valid string we should be able to
+            # retrieve the DecimalModel object without error
+            DecimalModel.objects.filter(decimal__lt=1)[0]
+        except InvalidOperation:
+            self.assertTrue(False)