can’t adapt type ‘Decimal’ error with Django + Apache + PostgreSQL + Psycopg2

One of my Django installation was running fine for a few months.  Last week I had to add a new Django project to this server.

My setup was : CentOS 5.5, Apache, mod_wsgi and psycopg2 2.2.0.x

After I added the new project, I started getting random errors « can’t adapt ». It would work perfectly for a few hours than my users would start getting an annyoying 500 error.

I searched the web, this seems to be a rather common error…but everything I found was related to another issue or something that was fixed in the Django release that I’m using.

One of the first thing I tryed was to update psycoppg2 to 2.2.1.

Now I was gettinga little bit information as the error was now « can’t adapt type ‘Decimal’ ».  That’s better, but I still didn’t know how to fix it.

I ended up posting a message in the django-user mailing.

Some nice folks had exactly the same problem and told me how to fix it.  I simply had to change mod_wsgi configuration so that it would run on his own process group.

My original configuration  :

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

Is now :

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

The only thing I find hard to understand is how undocumented that issue is.  I wouldn’t think that I am the only one running with that kind of setup ?

  • Share/Bookmark

7 Responses to “can’t adapt type ‘Decimal’ error with Django + Apache + PostgreSQL + Psycopg2”

  1. Gabriel Farrell Says:

    Thanks, 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 the only place where « process-group » is mentioned is in the WSGIImportScript section.

  2. Étienne Pouliot Says:

    Glag I could help ;)

    I also find it odd that this parameter isn’t well docuemented, espcially since not using it cause random errors.

  3. Sophie Hume Says:

    Merci Bien! Thank you! I’ve been tearing my hair out for days over this one, and your fix worked a treat.

  4. Lex Toumbourou Says:

    Brilliant. Thanks for this mate.

  5. Says:

    J’ai enfin trouvé un article intéréssant sur le thème de can’t adapt type ‘Decimal’ error with Django + Apache + PostgreSQL + Psycopg2 | Le blog d’Étienne Pouliot

  6. “can’t adapt type decimal” Error | Coding Simplicity Says:

    [...] Sometimes we'd get it once every 10 seconds, sometimes it wouldn't show for days. Finally we found this blog post with a solution, but I wanted to provide my own spin on it. But first (as right now I'm assuming [...]

Comments are closed.