Re: unsupported operand type(s) for *: 'Decimal' and 'Decimal'

144 views
Skip to first unread message

Landlord Bulfleet

unread,
Sep 19, 2007, 12:41:50 PM9/19/07
to django...@googlegroups.com
We have the following weird problem, that we are unable to deliberately replicate no matter what we try...

It seems to appears only when our server (running python2.5.1, daily updated django svn, mod_python 3.3.1) has been running for at least maybe 4-5 hours...
After an apache restart there is no sign of the bug for another 5-7 hours...

The weird thing is that calling the view with the exactly the same parameters usually doesn't reproduce the error.

=== sample code ===
(class1, class2) = (sum.__class__, f_c.rate.__class__)
d_sum = sum * f_c.rate                                                     <-  break

Local vars:
class1 <class 'decimal.Decimal'>
class2 <class 'decimal.Decimal'>
sum Decimal("0.23")
=== ===

sum is property of a model object in our database (models.DecimalField(max_digits=7, decimal_places=2)) & f_c.rate is a  Decimal constructed using Decimal(string) construction (Decimal is imported with "from decimal import Decimal")

We have some doubts that this may be a result of the django's python 2.3 _decimal compatibility.

Any help is appreciated...

Jeremy Dunck

unread,
Sep 19, 2007, 9:18:54 PM9/19/07
to django...@googlegroups.com
On 9/19/07, Landlord Bulfleet <landlo...@gmail.com> wrote:
...

>
> sum is property of a model object in our database
> (models.DecimalField(max_digits=7, decimal_places=2)) & f_c.rate is a
> Decimal constructed using Decimal(string) construction (Decimal is imported
> with "from decimal import Decimal")
>
> We have some doubts that this may be a result of the django's python 2.3
> _decimal compatibility.

You're using PsycoPG with multiple interpreters. :)

http://www.initd.org/tracker/psycopg/ticket/192
http://groups.google.com/group/django-developers/browse_thread/thread/63046b2fca27673c/898dbf8da327ce71

Anyway, I did run into this using psycopg1, but switched to psycopg2
and patched it since 1) it's being maintained and 2) it was easier to
fix that way.

I emailed the psycopg list a couple weeks ago with a patch but never
heard back from them. I don't have rights to add the patch to their
ticket tracker, or I'd do that, too.

I'm attaching a patch against psycopg2's source code here. This is
for r896 on the 2.0.x branch.

Alternatively, you could run separate apache processes for each needed
interpreter or switch to mod_wsgi.

I wasn't prepared to swtich to mod_wsgi in a hurry, so patched
psycopg2 instead.

Apparently not that many people are using multiple interpreters and
decimal fields with psycopg...

psycopg2-2.0.x-896-decimal.diff

Landlord Bulfleet

unread,
Sep 20, 2007, 10:43:47 AM9/20/07
to django...@googlegroups.com
Thanks :)

Looks like this is the solution to our problem. We haven't tested it yet but will try soon.

Thanks again
Reply all
Reply to author
Forward
0 new messages