diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-01-03 04:59:05 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-01-03 04:59:05 +0000 |
| commit | f2986d89b9fe74ebfc9d544324333c9ebde84ad5 (patch) | |
| tree | 7d32ac618e3c296dc2a9b8da4e39af428402ef34 /tests/regressiontests | |
| parent | 94b83db4995ea8b763fef607141a246cb5c52c37 (diff) | |
[1.0.X] Fixed #9942 -- Added a to_python handler for FloatField to ensure correct typing of deserialized data before saving. Underlying problem is analogous to #8298, fixed in [8515]. Thanks to David Larlet <larlet@gmail.com> for the report and fix.
Backport of r9695 and r9696 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9697 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
3 files changed, 9 insertions, 4 deletions
diff --git a/tests/regressiontests/fixtures_regress/fixtures/animal.xml b/tests/regressiontests/fixtures_regress/fixtures/animal.xml index 1a993b523d..0383c60fc1 100644 --- a/tests/regressiontests/fixtures_regress/fixtures/animal.xml +++ b/tests/regressiontests/fixtures_regress/fixtures/animal.xml @@ -4,5 +4,6 @@ <field type="CharField" name="name">Emu</field> <field type="CharField" name="latin_name">Dromaius novaehollandiae</field> <field type="IntegerField" name="count">42</field> + <field type="FloatField" name="weight">1.2</field> </object> </django-objects>
\ No newline at end of file diff --git a/tests/regressiontests/fixtures_regress/fixtures/sequence.json b/tests/regressiontests/fixtures_regress/fixtures/sequence.json index 122ebf2073..60bfcdd547 100644 --- a/tests/regressiontests/fixtures_regress/fixtures/sequence.json +++ b/tests/regressiontests/fixtures_regress/fixtures/sequence.json @@ -5,7 +5,8 @@ "fields": { "name": "Lion", "latin_name": "Panthera leo", - "count": 3 + "count": 3, + "weight": 1.2 } } ]
\ No newline at end of file diff --git a/tests/regressiontests/fixtures_regress/models.py b/tests/regressiontests/fixtures_regress/models.py index 373980bb66..621c80c15f 100644 --- a/tests/regressiontests/fixtures_regress/models.py +++ b/tests/regressiontests/fixtures_regress/models.py @@ -7,6 +7,7 @@ class Animal(models.Model): name = models.CharField(max_length=150) latin_name = models.CharField(max_length=150) count = models.IntegerField() + weight = models.FloatField() def __unicode__(self): return self.common_name @@ -14,6 +15,7 @@ class Animal(models.Model): def animal_pre_save_check(signal, sender, instance, **kwargs): "A signal that is used to check the type of data loaded from fixtures" print 'Count = %s (%s)' % (instance.count, type(instance.count)) + print 'Weight = %s (%s)' % (instance.weight, type(instance.weight)) class Plant(models.Model): name = models.CharField(max_length=150) @@ -69,7 +71,7 @@ __test__ = {'API_TESTS':""" # Create a new animal. Without a sequence reset, this new object # will take a PK of 1 (on Postgres), and the save will fail. # This is a regression test for ticket #3790. ->>> animal = Animal(name='Platypus', latin_name='Ornithorhynchus anatinus', count=2) +>>> animal = Animal(name='Platypus', latin_name='Ornithorhynchus anatinus', count=2, weight=2.3) >>> animal.save() ############################################### @@ -149,12 +151,13 @@ No fixture data found for 'bad_fixture2'. (File format may be invalid.) [1, 2, 3, 4, 5, 6, 7, 8] ############################################### -# Test for ticket #8298 - Field values should be coerced into the correct type -# by the deserializer, not as part of the database write. +# Test for tickets #8298, #9942 - Field values should be coerced into the +# correct type by the deserializer, not as part of the database write. >>> models.signals.pre_save.connect(animal_pre_save_check) >>> management.call_command('loaddata', 'animal.xml', verbosity=0) Count = 42 (<type 'int'>) +Weight = 1.2 (<type 'float'>) >>> models.signals.pre_save.disconnect(animal_pre_save_check) |
