|
14 | 14 | from plain.models.backends.base.validation import BaseDatabaseValidation |
15 | 15 | from plain.models.backends.utils import debug_transaction |
16 | 16 | from plain.models.db import ( |
17 | | - DEFAULT_DB_ALIAS, |
18 | 17 | DatabaseError, |
19 | 18 | DatabaseErrorWrapper, |
20 | 19 | NotSupportedError, |
21 | 20 | ) |
22 | 21 | from plain.models.transaction import TransactionManagementError |
23 | 22 | from plain.runtime import settings |
24 | 23 |
|
25 | | -NO_DB_ALIAS = "__no_db__" |
26 | | -RAN_DB_VERSION_CHECK = set() |
| 24 | +RAN_DB_VERSION_CHECK = False |
27 | 25 |
|
28 | 26 | logger = logging.getLogger("plain.models.backends.base") |
29 | 27 |
|
@@ -51,15 +49,14 @@ class BaseDatabaseWrapper: |
51 | 49 |
|
52 | 50 | queries_limit = 9000 |
53 | 51 |
|
54 | | - def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS): |
| 52 | + def __init__(self, settings_dict): |
55 | 53 | # Connection related attributes. |
56 | 54 | # The underlying database connection. |
57 | 55 | self.connection = None |
58 | 56 | # `settings_dict` should be a dictionary containing keys such as |
59 | 57 | # NAME, USER, etc. It's called `settings_dict` instead of `settings` |
60 | 58 | # to disambiguate it from Plain settings modules. |
61 | 59 | self.settings_dict = settings_dict |
62 | | - self.alias = alias |
63 | 60 | # Query logging in debug mode or when explicitly enabled. |
64 | 61 | self.queries_log = deque(maxlen=self.queries_limit) |
65 | 62 | self.force_debug_cursor = False |
@@ -120,10 +117,7 @@ def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS): |
120 | 117 | self.validation = self.validation_class(self) |
121 | 118 |
|
122 | 119 | def __repr__(self): |
123 | | - return ( |
124 | | - f"<{self.__class__.__qualname__} " |
125 | | - f"vendor={self.vendor!r} alias={self.alias!r}>" |
126 | | - ) |
| 120 | + return f"<{self.__class__.__qualname__} vendor={self.vendor!r}>" |
127 | 121 |
|
128 | 122 | def ensure_timezone(self): |
129 | 123 | """ |
@@ -218,9 +212,9 @@ def get_new_connection(self, conn_params): |
218 | 212 | def init_connection_state(self): |
219 | 213 | """Initialize the database connection settings.""" |
220 | 214 | global RAN_DB_VERSION_CHECK |
221 | | - if self.alias not in RAN_DB_VERSION_CHECK: |
| 215 | + if not RAN_DB_VERSION_CHECK: |
222 | 216 | self.check_database_version_supported() |
223 | | - RAN_DB_VERSION_CHECK.add(self.alias) |
| 217 | + RAN_DB_VERSION_CHECK = True |
224 | 218 |
|
225 | 219 | def create_cursor(self, name=None): |
226 | 220 | """Create a cursor. Assume that a connection is established.""" |
@@ -593,8 +587,8 @@ def validate_thread_sharing(self): |
593 | 587 | if not (self.allow_thread_sharing or self._thread_ident == _thread.get_ident()): |
594 | 588 | raise DatabaseError( |
595 | 589 | "DatabaseWrapper objects created in a " |
596 | | - "thread can only be used in that same thread. The object " |
597 | | - f"with alias '{self.alias}' was created in thread id {self._thread_ident} and this is " |
| 590 | + "thread can only be used in that same thread. The connection " |
| 591 | + f"was created in thread id {self._thread_ident} and this is " |
598 | 592 | f"thread id {_thread.get_ident()}." |
599 | 593 | ) |
600 | 594 |
|
@@ -656,7 +650,7 @@ def _nodb_cursor(self): |
656 | 650 | being exposed to potential child threads while (or after) the test |
657 | 651 | database is destroyed. Refs #10868, #17786, #16969. |
658 | 652 | """ |
659 | | - conn = self.__class__({**self.settings_dict, "NAME": None}, alias=NO_DB_ALIAS) |
| 653 | + conn = self.__class__({**self.settings_dict, "NAME": None}) |
660 | 654 | try: |
661 | 655 | with conn.cursor() as cursor: |
662 | 656 | yield cursor |
@@ -729,13 +723,11 @@ def execute_wrapper(self, wrapper): |
729 | 723 | finally: |
730 | 724 | self.execute_wrappers.pop() |
731 | 725 |
|
732 | | - def copy(self, alias=None): |
| 726 | + def copy(self): |
733 | 727 | """ |
734 | 728 | Return a copy of this connection. |
735 | 729 |
|
736 | 730 | For tests that require two connections to the same database. |
737 | 731 | """ |
738 | 732 | settings_dict = copy.deepcopy(self.settings_dict) |
739 | | - if alias is None: |
740 | | - alias = self.alias |
741 | | - return type(self)(settings_dict, alias) |
| 733 | + return type(self)(settings_dict) |
0 commit comments