Throwing the following DatabaseError in Django 1.5.1 (and 1.5.0) and mysql when I runserver and attempt to load a local version of the web app:
DatabaseError at /
DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias 'default' was created in thread id 4365488128 and this is thread id 140735183980896.
The exception location is as follows:
/Users/USERNAME/.envs/PROJECT_NAME/lib/python2.7/site-packages/django/db/backends/init.py in validate_thread_sharing, line 154
This happens only on the first page load. When I hit refresh the the web app loads as expected. The error returns when I alter Django/python code and the local server needs to re-validate. When that happens the first load once again throws the DatabaseError and subsequent loads once again do not.
This issue is only happening on my Django 1.5 projects. I've uninstalled mysql and cleared the mysql binary files located in /usr/local/var/mysql. A fresh install of mysql has not solved this issue.
A similar DatabaseError is discussed here but I'm not able to follow their solution:
https://code.djangoproject.com/ticket/17998
I'm at a loss here, any ideas or expertise would be appreciated. Thank you.
I solved the issue by monkey patching before imports of django.*:
import eventlet
eventlet.monkey_patch()
You understood than I use threads here.
This is for 1.4, but the cause of the problem may be the same as yours:
https://bitbucket.org/akoha/django-digest/issue/10/conflict-with-global-databasewrapper
Two possible solutions in that post, though both appear to be workarounds:
"I have been able to fix the problem by commenting out close_connection in db.py"
"One fix that will definitely work is to replace MultiDb/get_default_db()/self.db by django.db.connection and django.db.tranasction as documented at: https://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With