can't adapt type 'Decimal'

242 views
Skip to first unread message

poupou

unread,
Jun 25, 2010, 9:06:27 AM6/25/10
to Django users
Hi,

I'm getting the error "can't adapt type 'Decimal'" from time to
time in my Django web site. Once I restart Apache it will works for
few hours, then some users will start to get this error.

Of the 2 web site that I have, It only happens where I make request
using the the Q objects.

For example this request :

projets = Projet.objects.filter(Q(termine = u'Non') |
Q(heure_difference__gt = 0 |
Q(termine = u'Oui') &
Q(base_renumeration = u'Forfait'))
for projet in projets:


Wich will end up and with the following traceback :

Traceback:
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py"
in get_response
92. response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/auth/
decorators.py" in __call__
78. return self.view_func(request, *args, **kwargs)
File "/var/www/django/defitek/gestion/views.py" in projet_en_cours
128. for projet in projets:
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in
_result_iter
106. self._fill_cache()
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in
_fill_cache
692.
self._result_cache.append(self._iter.next())
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in
iterator
238. for row in self.query.results_iter():
File "/usr/lib/python2.4/site-packages/django/db/models/sql/query.py"
in results_iter
287. for rows in self.execute_sql(MULTI):
File "/usr/lib/python2.4/site-packages/django/db/models/sql/query.py"
in execute_sql
2369. cursor.execute(sql, params)
File "/usr/lib/python2.4/site-packages/django/db/backends/util.py" in
execute
19. return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /projet_en_cours/
Exception Value: can't adapt type 'Decimal'

Here are the value that it tryed to use in the request :

return self.cursor.execute(sql, params) ...
▶ Local vars
Variable
Value
params
(u'Non', Decimal("0"), u'Oui', u'Forfait')
self
<django.db.backends.util.CursorDebugWrapper object at 0x9a585ec>
sql
None
start
1277468406.010195
stop
1277468406.010242

I'm using : Django 1.1.1, CentOS 5.5, Python-2.4.3-27, mod_wsgi 3.2
and psycopg2-2.2.1

I read many thread that had a can't adapt error, it seems to be
something wrong with psycopg2. But I have yet to figure out how to
fix this.

Please help. Thank you.

Stuart

unread,
Jun 25, 2010, 10:06:23 AM6/25/10
to Django users
On Jun 25, 8:06 am, poupou <etiennepoul...@gmail.com> wrote:
>
>   Of the 2 web site that I have, It only happens where I make request
> using the the Q objects.
>

Your problem sounds like the problem I just went through. I assume you
are using mod_wsgi. Are the two sites on the same server? For example,
you have one at http://myserver/app1 and the other at http://myserver/app2
-- is that right?

If that's your scenario, upgrade to the latest version of mod_wsgi and
set it to run in daemon mode. For details on how to do that, see here:
http://groups.google.com/group/satchmo-users/msg/a9b22c236d63c323


Hope that helps,

--Stuart

Stuart

unread,
Jun 25, 2010, 10:51:19 AM6/25/10
to Django users, stu...@bistrotech.net
On Jun 25, 8:06 am, poupou <etiennepoul...@gmail.com> wrote:
>
>   Of the 2 web site that I have, It only happens where I make request
> using the the Q objects.
>

If you have two django sites/projects on the same server (e.g.
http://myserver/app1 and http://myserver/app2) and you are using
mod_wsgi, I bet you're having the same problem I was. To fix it,
upgrade to the latest version of mod_wsgi and run it in daemon mode.
See here for details: http://groups.google.com/group/satchmo-users/msg/a9b22c236d63c323


Hope that helps,

--Stuart

poupou

unread,
Jun 25, 2010, 1:12:10 PM6/25/10
to Django users
Yes I'm running two sites on the same server. Only difference with
you is that I'm running it with virtual host.

I modifier my Apache config, now it looks like this :

<VirtualHost *:443>
ServerName site1.com
WSGIDaemonProcess site1
WSGIScriptAlias / /var/www/site1.wsgi process-group=site1
application-group=%{GLOBAL}

</VirtualHost>

<VirtualHost *:443>
ServerName site2.com
WSGIDaemonProcess site2
WSGIScriptAlias / /var/www/site2.wsgi process-group=site2
application-group=%{GLOBAL}

</VirtualHost>

It will take a little to make sure it's working, I will report on this
thread if everything is ok.

Thank you!

On 25 juin, 10:51, Stuart <stu...@bistrotech.net> wrote:
> On Jun 25, 8:06 am, poupou <etiennepoul...@gmail.com> wrote:
>
>
>
> >   Of the 2 web site that I have, It only happens where I make request
> > using the the Q objects.
>
> If you have two django sites/projects on the same server (e.g.http://myserver/app1andhttp://myserver/app2) and you are using

poupou

unread,
Jun 28, 2010, 5:01:02 PM6/28/10
to Django users
I confirm that everything is working fine now.

Thank you again.

Gabriel Farrell

unread,
Aug 24, 2010, 12:16:56 PM8/24/10
to Django users
(I tried to post the below in a comment at poupou's site (http://
www.defitek.com/blog/2010/06/29/cant-adapt-type-decimal-error-with-django-apache-postgresql-psycopg2/),
but kept getting errors.)

Just ran into the same problem. In my mod_wsgi config I had:

WSGIDaemonProcess site1 maximum-requests=10000
WSGIProcessGroup site1
WSGIScriptAlias /site1 /var/www/site1/django.wsgi

WSGIDaemonProcess site2 maximum-requests=10000
WSGIProcessGroup site2
WSGIScriptAlias /site2 /var/www/site2/django.wsgi

I was getting errors with that, but with the "process-group" parameter
things are running fine. Funny that at http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives
the only place where "process-group" is mentioned is in the
WSGIImportScript section.
Reply all
Reply to author
Forward
0 new messages