pdb.set_trace(), decimal, django, FloatField

!#%@#^@#$%@#% Decimal.

So the other evening was spent tracking down a damnable thing. in Python 2.4, the win32 implementation of Decimal (new in Python 2.4) doesn’t support multiplying a Decimal value by an integer. And that really bit hard.

Turns out, the whole reason I was dealing with Decimal was because of a terrible assumption I made. Somewhere in a recent version of the python MySQL drivers, they slipped in a return value type of Decimal for floats… damnit. Freakin’ bit me in the butt. Turns out that Django with MySQL on my MacOS X box was giving me back a Decimal python type when the python value was retrieved from a django FloatField. Win32, however, was returning a float.

Grrrr…

In the end, I did a terrible thing – I put in an OS specific check in my code to convert the bloody thing to float so that it would at least be consistent. decimal.Decimal includes a handy .__float__() method.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s