Author: mtredinnick
Date: 2009-04-12 00:32:23 -0500 (Sun, 12 Apr 2009)
New Revision: 10545

Modified:
   django/trunk/django/db/models/fields/__init__.py
   django/trunk/tests/regressiontests/model_fields/tests.py
Log:
Fixed #10692 -- Fixed DecimalField lookups for extreme values.

Modified: django/trunk/django/db/models/fields/__init__.py
===================================================================
--- django/trunk/django/db/models/fields/__init__.py    2009-04-12 04:57:50 UTC 
(rev 10544)
+++ django/trunk/django/db/models/fields/__init__.py    2009-04-12 05:32:23 UTC 
(rev 10545)
@@ -620,10 +620,13 @@
         from django.db.backends import util
         return util.format_number(value, self.max_digits, self.decimal_places)
 
-    def get_db_prep_value(self, value):
+    def get_db_prep_save(self, value):
         return connection.ops.value_to_db_decimal(self.to_python(value),
                 self.max_digits, self.decimal_places)
 
+    def get_db_prep_value(self, value):
+        return self.to_python(value)
+
     def formfield(self, **kwargs):
         defaults = {
             'max_digits': self.max_digits,

Modified: django/trunk/tests/regressiontests/model_fields/tests.py
===================================================================
--- django/trunk/tests/regressiontests/model_fields/tests.py    2009-04-12 
04:57:50 UTC (rev 10544)
+++ django/trunk/tests/regressiontests/model_fields/tests.py    2009-04-12 
05:32:23 UTC (rev 10545)
@@ -1,32 +1,35 @@
 import datetime
 import unittest
+
 import django.test
 from django import forms
 from django.db import models
 from django.core.exceptions import ValidationError
+
 from models import Foo, Bar, Whiz, BigD, BigS
+
 try:
     from decimal import Decimal
 except ImportError:
     from django.utils._decimal import Decimal
-    
+
 class DecimalFieldTests(django.test.TestCase):
     def test_to_python(self):
         f = models.DecimalField(max_digits=4, decimal_places=2)
         self.assertEqual(f.to_python(3), Decimal("3"))
         self.assertEqual(f.to_python("3.14"), Decimal("3.14"))
         self.assertRaises(ValidationError, f.to_python, "abc")
-    
+
     def test_default(self):
         f = models.DecimalField(default=Decimal("0.00"))
         self.assertEqual(f.get_default(), Decimal("0.00"))
-    
+
     def test_format(self):
         f = models.DecimalField(max_digits=5, decimal_places=1)
         self.assertEqual(f._format(f.to_python(2)), u'2.0')
         self.assertEqual(f._format(f.to_python('2.6')), u'2.6')
         self.assertEqual(f._format(None), None)
-    
+
     def test_get_db_prep_lookup(self):
         f = models.DecimalField(max_digits=5, decimal_places=1)
         self.assertEqual(f.get_db_prep_lookup('exact', None), [None])
@@ -38,7 +41,7 @@
         Foo.objects.create(id=1, a='abc', d=Decimal("12.34"))
         self.assertEqual(list(Foo.objects.filter(d=u'1.23')), [])
 
-    def test_save_wihout_float_conversion(self):
+    def test_save_without_float_conversion(self):
         """
         Ensure decimals don't go through a corrupting float conversion during
         save (#5079).
@@ -48,6 +51,14 @@
         bd = BigD.objects.get(pk=bd.pk)
         self.assertEqual(bd.d, Decimal("12.9"))
 
+    def test_lookup_really_big_value(self):
+        """
+        Ensure that really big values can be used in a filter statement, even
+        with older Python versions.
+        """
+        # This should not crash. That counts as a win for our purposes.
+        Foo.objects.filter(d__gte=100000000000)
+
 class ForeignKeyTests(django.test.TestCase):
     def test_callable_default(self):
         """Test the use of a lazy callable for ForeignKey.default"""
@@ -63,11 +74,11 @@
                          datetime.datetime(2001, 1, 2, 3, 4, 5, 6))
         self.assertEqual(f.to_python('2001-01-02 03:04:05.999999'),
                          datetime.datetime(2001, 1, 2, 3, 4, 5, 999999))
-        
+
     def test_timefield_to_python_usecs(self):
         """TimeField.to_python should support usecs"""
         f = models.TimeField()
-        self.assertEqual(f.to_python('01:02:03.000004'), 
+        self.assertEqual(f.to_python('01:02:03.000004'),
                          datetime.time(1, 2, 3, 4))
         self.assertEqual(f.to_python('01:02:03.999999'),
                          datetime.time(1, 2, 3, 999999))
@@ -111,7 +122,7 @@
         self.assertEqual(Whiz(c=9).get_c_display(), 9)          # Invalid value
         self.assertEqual(Whiz(c=None).get_c_display(), None)    # Blank value
         self.assertEqual(Whiz(c='').get_c_display(), '')        # Empty value
-        
+
 class SlugFieldTests(django.test.TestCase):
     def test_slugfield_max_length(self):
         """
@@ -119,4 +130,5 @@
         """
         bs = BigS.objects.create(s = 'slug'*50)
         bs = BigS.objects.get(pk=bs.pk)
-        self.assertEqual(bs.s, 'slug'*50)
\ No newline at end of file
+        self.assertEqual(bs.s, 'slug'*50)
+


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to