本文整理汇总了Python中django.db.backends.base.base.BaseDatabaseWrapper方法的典型用法代码示例。如果您正苦于以下问题:Python base.BaseDatabaseWrapper方法的具体用法?Python base.BaseDatabaseWrapper怎么用?Python base.BaseDatabaseWrapper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.backends.base.base
的用法示例。
在下文中一共展示了base.BaseDatabaseWrapper方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_instance
# 需要导入模块: from django.db.backends.base import base [as 别名]
# 或者: from django.db.backends.base.base import BaseDatabaseWrapper [as 别名]
def test_instance():
settings_dict = {
}
driver = base.DatabaseWrapper(settings_dict)
assert isinstance(driver, BaseDatabaseWrapper)
示例2: assertConnectionsEnabled
# 需要导入模块: from django.db.backends.base import base [as 别名]
# 或者: from django.db.backends.base.base import BaseDatabaseWrapper [as 别名]
def assertConnectionsEnabled(self):
for alias in connections:
self.assertThat(
connections[alias], IsInstance(BaseDatabaseWrapper)
)
示例3: monkeypatch_django
# 需要导入模块: from django.db.backends.base import base [as 别名]
# 或者: from django.db.backends.base.base import BaseDatabaseWrapper [as 别名]
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