diff --git a/django/db/backends/base/base.py b/django/db/backends/base/base.py
index 3b845ec9b3..c88162a246 100644
a
|
b
|
import logging
|
5 | 5 | import threading |
6 | 6 | import time |
7 | 7 | import warnings |
| 8 | import weakref |
8 | 9 | from collections import deque |
9 | 10 | from contextlib import contextmanager |
10 | 11 | |
… |
… |
class BaseDatabaseWrapper:
|
125 | 126 | # call execute(sql, params, many, context). |
126 | 127 | self.execute_wrappers = [] |
127 | 128 | |
128 | | self.client = self.client_class(self) |
129 | | self.creation = self.creation_class(self) |
130 | | self.features = self.features_class(self) |
131 | | self.introspection = self.introspection_class(self) |
132 | | self.ops = self.ops_class(self) |
133 | | self.validation = self.validation_class(self) |
| 129 | weak_self = weakref.proxy(self) |
| 130 | self.client = self.client_class(weak_self) |
| 131 | self.creation = self.creation_class(weak_self) |
| 132 | self.features = self.features_class(weak_self) |
| 133 | self.introspection = self.introspection_class(weak_self) |
| 134 | self.ops = self.ops_class(weak_self) |
| 135 | self.validation = self.validation_class(weak_self) |
134 | 136 | |
135 | 137 | def __repr__(self): |
136 | 138 | return ( |
… |
… |
class BaseDatabaseWrapper:
|
674 | 676 | Context manager and decorator that re-throws backend-specific database |
675 | 677 | exceptions using Django's common wrappers. |
676 | 678 | """ |
677 | | return DatabaseErrorWrapper(self) |
| 679 | return DatabaseErrorWrapper(weakref.proxy(self)) |
678 | 680 | |
679 | 681 | def chunked_cursor(self): |
680 | 682 | """ |
diff --git a/tests/backends/sqlite/tests.py b/tests/backends/sqlite/tests.py
index 88b514270a..eda7ff54a4 100644
a
|
b
|
class Tests(TestCase):
|
71 | 71 | "NAME": "file:memorydb_test?mode=memory&cache=shared", |
72 | 72 | } |
73 | 73 | } |
74 | | creation = DatabaseWrapper(settings_dict).creation |
| 74 | db = DatabaseWrapper(settings_dict) |
| 75 | creation = db.creation |
75 | 76 | self.assertEqual( |
76 | 77 | creation._get_test_db_name(), |
77 | 78 | creation.connection.settings_dict["TEST"]["NAME"], |