On Tue, Jul 28, 2009 at 4:14 PM, Dave MacFarlane <
dave.macfarl...@ecometrica.ca> wrote:

>
> Hello,
>
> I'm experiencing an unusual problem with django where it's sometimes
> throwing a TypeError exception with the exception value "unsupported
> operand type(s) for *: 'Decimal' and 'Decimal'" when multiplying a
> DecimalField by a Decimal. This seems to happen for about 20% of
> requests to a view, and is more frequent when the requests are
> concurrent.
>
> The code that's throwing the exception is the first return in this
> simple class method on a model:
>
> def CO2e(self, *args, **kwargs):
>     if(kwargs.get('qty', None) != None):
>         return self.factor*self.type.equivalency*Decimal(kwargs['qty'])
>     return self.factor*self.type.equivalency
>
> where factor and equivalency are both django DecimalFields on models,
> and Decimal is the standard python Decimal class from the decimal
> package.
>
> (According to the exception page the value of kwargs is {'qty':
> u'464.02'} in the case I'm currently debugging. It doesn't what the
> value of qty is, it's a unicode string which the Decimal class should
> be able to handle.)
>
> The only somewhat related information I can find online is this thread:
>
> http://groups.google.com/group/django-users/browse_thread/thread/91aa6c088f6c090/929f2fd69307cd22
>
> but the link to the the psycopg ticket no longer works and just goes
> to a rant about how the author hates trac. I'm not convinced that it
> is that bug since the environment is already running under mod_wsgi,
> which the django-users thread suggests fixes the problem. The
> environment is using the postgres database engine, and has psycopg
> 2.0.7 installed on it.
>
> So a couple of questions:
> 1. Is the bug described in that thread still an issue? It's a fairly
> old thread.
> 2. Does anyone have any suggestions for where else to poke for
> debugging this?
>

I don't know if it's still an issue but I have a vague recollection of
seeing a similar problem mentioned fairly recently, and reported as fixed by
upgrading psycopg2.  I'm not up on psycopg2 levels -- is 2.0.7 the latest?

You can see the original problem report here:

http://lists.initd.org/pipermail/psycopg/2007-July/005565.html

and it states the problem may also occur under mod_wsgi.  The "fixed by
running under mod_wsgi" implication may be because you can configure things
under mod_wsgi such that you don't have multiple Python sub interpreters,
but if your configuration doesn't ensure that then I think you can still see
the problem under mod_wsgi.  So an alternative way to fix/debug it may be to
ensure your mod_wsgi configuration does not result in the problem situation
described in that ticket.

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to