﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
8050	DecimalField no longer takes float values	Karen Tracey <kmtracey@…>	nobody	"As of r8143, given a model like this:

{{{

class Dec(models.Model):
    avg = models.DecimalField(decimal_places=2, max_digits=5)

}}}

I'm seeing failures like this:

{{{
>>> d1 = Dec(avg=2.3)
>>> d1.save()
Traceback (most recent call last):
  File ""<console>"", line 1, in <module>
  File ""d:\u\kmt\django\trunk\django\db\models\base.py"", line 274, in save
    self.save_base()
  File ""d:\u\kmt\django\trunk\django\db\models\base.py"", line 330, in save_base
    values = [(f, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, True))) for f in meta.local_fields if not isinstance(f, AutoField)]
  File ""d:\u\kmt\django\trunk\django\db\models\fields\__init__.py"", line 232, in get_db_prep_save
    return self.get_db_prep_value(value)
  File ""d:\u\kmt\django\trunk\django\db\models\fields\__init__.py"", line 735, in get_db_prep_value
    return connection.ops.value_to_db_decimal(self.to_python(value),
  File ""d:\u\kmt\django\trunk\django\db\models\fields\__init__.py"", line 709, in to_python
    return decimal.Decimal(value)
  File ""d:\bin\Python2.5.1\lib\decimal.py"", line 578, in __new__
    ""First convert the float to a string"")
TypeError: Cannot convert float to Decimal.  First convert the float to a string
>>>
}}}

Prior to r8143 code like this worked fine.  Now I realize it's called !DecimalField, so perhaps I should be passing in a Decimal not a float, but when originally written this code (not the above but the code where I actually hit the problem) used a !FloatField, and at some point I migrated it to !DecimalField via these instructions:

http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges#RenamedFloatFieldtoDecimalField

which don't mention anywhere the need to migrate to passing in Decimals for the values.  Is the intent to no longer allow passing floats here?  If so it probably needs a mention in Backwards Incompatible Changes."		closed	Documentation	dev		fixed			Accepted	0	0	0	0	0	0
