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.

Published by heckj

Developer, author, and life-long student. Writes online at https://rhonabwy.com/.

%d bloggers like this: