Python django.db.backends.base.base.BaseDatabaseWrapper() Examples

The following are 4 code examples for showing how to use django.db.backends.base.base.BaseDatabaseWrapper(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

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
Project: django-arangodb   Author: pablotcarreira   File: test_arangodb_driver.py    License: Apache License 2.0 5 votes vote down vote up
def test_instance():
    settings_dict = {
    }

    driver = base.DatabaseWrapper(settings_dict)
    assert isinstance(driver, BaseDatabaseWrapper) 
Example 2
Project: maas   Author: maas   File: test_orm.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def assertConnectionsEnabled(self):
        for alias in connections:
            self.assertThat(
                connections[alias], IsInstance(BaseDatabaseWrapper)
            ) 
Example 3
Project: maas   Author: maas   File: test_plugin.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def assertConnectionsEnabled(self):
        for alias in connections:
            self.assertThat(
                connections[alias], IsInstance(BaseDatabaseWrapper)
            ) 
Example 4
Project: django-dbconn-retry   Author: jdelic   File: __init__.py    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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