#30171: Fix DatabaseError threading error during servers tests
-------------------------------------+-------------------------------------
Reporter: Jon Dufresne | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):
* needs_better_patch: 1 => 0
* version: master => 2.2
* stage: Accepted => Ready for checkin
Old description:
> When running tests with Python warnings enabled, `LiveServerPort`
> produces a warning of the form:
>
> {{{
> Exception in thread Thread-1:
> Traceback (most recent call last):
> File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner
> self.run()
> File "django/test/testcases.py", line 1399, in run
> connections.close_all()
> File "django/db/utils.py", line 224, in close_all
> connection.close()
> File "django/db/backends/sqlite3/base.py", line 244, in close
> self.validate_thread_sharing()
> File "django/db/backends/base/base.py", line 531, in
> validate_thread_sharing
> % (self.alias, self._thread_ident, _thread.get_ident())
> django.db.utils.DatabaseError: DatabaseWrapper objects created in a
> thread can only be used in that same thread. The object with alias
> 'default' was created in thread id 139685002331648 and this is thread id
> 139684747486976.
> }}}
>
> This occurs because multiple classes set
> `DatabaseWrapper.allow_thread_sharing` to false upon test tear down. The
> base test class and the temporarily created test class. In other words,
> nesting the setup/teardown of `DatabaseWrapper.allow_thread_sharing`
> isn't always handled cleanly.
New description:
When running tests with Python warnings enabled,
`tests.servers.tests.LiveServerPort` produces a warning of the form:
{{{
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "django/test/testcases.py", line 1399, in run
connections.close_all()
File "django/db/utils.py", line 224, in close_all
connection.close()
File "django/db/backends/sqlite3/base.py", line 244, in close
self.validate_thread_sharing()
File "django/db/backends/base/base.py", line 531, in
validate_thread_sharing
% (self.alias, self._thread_ident, _thread.get_ident())
django.db.utils.DatabaseError: DatabaseWrapper objects created in a thread
can only be used in that same thread. The object with alias 'default' was
created in thread id 139685002331648 and this is thread id
139684747486976.
}}}
This occurs because multiple classes set
`DatabaseWrapper.allow_thread_sharing` to false upon test tear down. The
base test class and the temporarily created test class. In other words,
nesting the setup/teardown of `DatabaseWrapper.allow_thread_sharing` isn't
always handled cleanly.
--
Comment:
The warning appeared after 8c775391b78b2a4a2b57c5e89ed4888f36aada4b, so
we'll backport to stable/2.2.x.
--
Ticket URL: <https://code.djangoproject.com/ticket/30171#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.3a8b9013e55b74fed4529a6eb0fe195e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.