Opened 6 years ago
Last modified 4 years ago
#30171 closed Cleanup/optimization
Fix Python warning during LiveServerPort — at Initial Version
Reported by: | Jon Dufresne | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 2.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
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.
Note:
See TracTickets
for help on using tickets.