Closed gthess closed 3 years ago
created a WIP pull request https://github.com/NLnetLabs/Internet.nl/pull/515
JS will add details on issue he ran into regarding database threading. Would be good if GT could also check how to deal with that.
I haven't looked at it but I suppose it happens because the db object is passed to other calls. That could be easily solved by passing the id instead and querying the db again.
The "problem" is in the file $your_local_python/dist-packages/django/db/backends/base/base.py
Specifically around line 540;
def validate_thread_sharing(self):
"""
Validate that the connection isn't accessed by another thread than the
one which originally created it, unless the connection was explicitly
authorized to be shared between threads (via the `inc_thread_sharing()`
method). Raise an exception if the validation fails.
"""
if not (self.allow_thread_sharing or self._thread_ident == _thread.get_ident()):
raise DatabaseError(
"DatabaseWrapper objects created in a "
"thread can only be used in that same thread. The object "
"with alias '%s' was created in thread id %s and this is "
"thread id %s."
% (self.alias, self._thread_ident, _thread.get_ident())
)
A bit of investigating into the history of this bit shows that it was mainly added because sqlite3 has trouble with the situation this is trying to fix. MySQL and Postgresql can safely ignore this entire issue and deal with threads just fine.
The psycopg2 postgres wrapper we're using doesn't seem to allow us to set allow_thread_sharing.
As a work-around for now I've simply added a "return" statement above the "if" in the function, but obviously we need something better.
Version 3.2 LTS: https://www.djangoproject.com/download/
fixed in upcoming release 1.4
Current code runs on the previous 1.11 LTS. We should at least go for 2.2 LTS or newest (3.2) by the time this issue is addressed.