Python django.db.backends.base.base.BaseDatabaseWrapper() Examples
The following are 4
code examples of django.db.backends.base.base.BaseDatabaseWrapper().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.db.backends.base.base
, or try the search function
.
Example #1
Source File: test_arangodb_driver.py From django-arangodb with Apache License 2.0 | 5 votes |
def test_instance(): settings_dict = { } driver = base.DatabaseWrapper(settings_dict) assert isinstance(driver, BaseDatabaseWrapper)
Example #2
Source File: test_orm.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def assertConnectionsEnabled(self): for alias in connections: self.assertThat( connections[alias], IsInstance(BaseDatabaseWrapper) )
Example #3
Source File: test_plugin.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def assertConnectionsEnabled(self): for alias in connections: self.assertThat( connections[alias], IsInstance(BaseDatabaseWrapper) )
Example #4
Source File: __init__.py From django-dbconn-retry with BSD 3-Clause "New" or "Revised" License | 4 votes |
def monkeypatch_django() -> None: def ensure_connection_with_retries(self: django_db_base.BaseDatabaseWrapper) -> None: if self.connection is not None and hasattr(self.connection, 'closed') and self.connection.closed: _log.debug("failed connection detected") self.connection = None if self.connection is None and not hasattr(self, '_in_connecting'): with self.wrap_database_errors: try: self._in_connecting = True self.connect() except Exception as e: if isinstance(e, _operror_types): if hasattr(self, "_connection_retries") and self._connection_retries >= 1: _log.error("Reconnecting to the database didn't help %s", str(e)) del self._in_connecting post_reconnect.send(self.__class__, dbwrapper=self) raise else: _log.info("Database connection failed. Refreshing...") # mark the retry self._connection_retries = 1 # ensure that we retry the connection. Sometimes .closed isn't set correctly. self.connection = None del self._in_connecting # give libraries like 12factor-vault the chance to update the credentials pre_reconnect.send(self.__class__, dbwrapper=self) self.ensure_connection() post_reconnect.send(self.__class__, dbwrapper=self) else: _log.debug("Database connection failed, but not due to a known error for dbconn_retry %s", str(e)) del self._in_connecting raise else: # connection successful, reset the flag self._connection_retries = 0 del self._in_connecting _log.debug("django_dbconn_retry: monkeypatching BaseDatabaseWrapper") django_db_base.BaseDatabaseWrapper.ensure_connection = ensure_connection_with_retries