Home

Fix for psyco in Django 1.0 query module

  • Oct. 23rd, 2008 at 3:42 PM
self
Today I enabled threaded (mpm worker) mod_python to try to boost performance of the RescueTime back end and started noticing the following error showing up in the logs:

File "/opt/lib/python2.5/site-packages/django/db/models/query.py", line 497, in _filter_or_exclude
clone = self._clone()
File "/opt/lib/python2.5/site-packages/django/db/models/query.py", line 595, in _clone
query = self.query.clone()
File "/opt/lib/python2.5/site-packages/django/db/models/sql/query.py", line 195, in clone
obj.__dict__.update(kwargs)
TypeError: descriptor '__dict__' for 'Empty' objects doesn't apply to 'Query' object'


The problem appears to be due to the magic that function does of
changing the runtime class of an object (which is explicitly listed as a known bug with using psyco on their site).

To fix it, I figured I'd just prevent that particular method from getting optimized by psyco, so I added this to the top of my models.py file:

from django.db import models
import psyco
psyco.cannotcompile(models.sql.query.Query.clone)


So far so good...