diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2008-08-24 08:12:13 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2008-08-24 08:12:13 +0000 |
| commit | 11e43883d55a17e39791f961aff952ef9e2c3ec5 (patch) | |
| tree | 580d735b456742bad78035ae5f2a891364676dd4 /tests | |
| parent | e822fd703bead9c753257da9722ea00e444395d5 (diff) | |
Fixed #8298: Added a to_python method for integer fields. This ensures that the data from deserialized instances is of correct type prior to saving. Thanks to Andrew Badr for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8515 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
3 files changed, 27 insertions, 3 deletions
diff --git a/tests/regressiontests/fixtures_regress/fixtures/animal.xml b/tests/regressiontests/fixtures_regress/fixtures/animal.xml new file mode 100644 index 0000000000..1a993b523d --- /dev/null +++ b/tests/regressiontests/fixtures_regress/fixtures/animal.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<django-objects version="1.0"> + <object pk="10" model="fixtures_regress.animal"> + <field type="CharField" name="name">Emu</field> + <field type="CharField" name="latin_name">Dromaius novaehollandiae</field> + <field type="IntegerField" name="count">42</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 ecaf637b9f..122ebf2073 100644 --- a/tests/regressiontests/fixtures_regress/fixtures/sequence.json +++ b/tests/regressiontests/fixtures_regress/fixtures/sequence.json @@ -4,7 +4,8 @@ "model": "fixtures_regress.animal", "fields": { "name": "Lion", - "latin_name": "Panthera leo" + "latin_name": "Panthera leo", + "count": 3 } } ]
\ No newline at end of file diff --git a/tests/regressiontests/fixtures_regress/models.py b/tests/regressiontests/fixtures_regress/models.py index 2c048dc0b8..9bca78bc59 100644 --- a/tests/regressiontests/fixtures_regress/models.py +++ b/tests/regressiontests/fixtures_regress/models.py @@ -6,10 +6,15 @@ import os class Animal(models.Model): name = models.CharField(max_length=150) latin_name = models.CharField(max_length=150) - + count = models.IntegerField() + def __unicode__(self): return self.common_name +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)) + class Plant(models.Model): name = models.CharField(max_length=150) @@ -64,7 +69,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') +>>> animal = Animal(name='Platypus', latin_name='Ornithorhynchus anatinus', count=2) >>> animal.save() ############################################### @@ -134,4 +139,14 @@ No fixture data found for 'bad_fixture2'. (File format may be invalid.) >>> articles.values_list('id', flat=True) [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. + +>>> models.signals.pre_save.connect(animal_pre_save_check) +>>> management.call_command('loaddata', 'animal.xml', verbosity=0) +Count = 42 (<type 'int'>) + +>>> models.signals.pre_save.disconnect(animal_pre_save_check) + """} |
