def check_variables(app_configs, **kwargs): if django.VERSION >= (3, 1): # when moving to Django 3.1+ only support, make this a real argument databases = kwargs["databases"] else: databases = {alias for alias, connection in mysql_connections()} errors = [] if databases is None: return errors databases = set(databases) for alias, connection in mysql_connections(): if alias not in databases: continue with connection.temporary_connection() as cursor: cursor.execute("""SELECT @@sql_mode, @@innodb_strict_mode, @@character_set_connection""") variables = cursor.fetchone() sql_mode, innodb_strict_mode, character_set_connection = variables modes = set(sql_mode.split(",")) if not (modes & {"STRICT_TRANS_TABLES", "STRICT_ALL_TABLES"}): errors.append(strict_mode_warning(alias)) if not innodb_strict_mode: errors.append(innodb_strict_mode_warning(alias)) if character_set_connection != "utf8mb4": errors.append(utf8mb4_warning(alias)) return errors
def check_variables( *, databases: Iterable[str] | None = None, **kwargs: Any, ) -> list[checks.CheckMessage]: errors: list[checks.CheckMessage] = [] if databases is None: return errors databases = set(databases) for alias, connection in mysql_connections(): if alias not in databases: continue with connection.temporary_connection() as cursor: cursor.execute("""SELECT @@innodb_strict_mode, @@character_set_connection""") variables = cursor.fetchone() innodb_strict_mode, character_set_connection = variables if not innodb_strict_mode: errors.append(innodb_strict_mode_warning(alias)) if character_set_connection != "utf8mb4": errors.append(utf8mb4_warning(alias)) return errors
def add_database_instrumentation(self): if not getattr(settings, "DJANGO_MYSQL_REWRITE_QUERIES", False): # pragma: no cover return for _alias, connection in mysql_connections(): install_rewrite_hook(connection) connection_created.connect(install_rewrite_hook)
def add_database_instrumentation(self): if not getattr(settings, "DJANGO_MYSQL_REWRITE_QUERIES", False): # pragma: no cover return for _alias, connection in mysql_connections(): # Rather than use the documented API of the `execute_wrapper()` # context manager, directly insert the hook. This is done because: # 1. Deleting the context manager closes it, so it's not possible # to enter it here and not exit it, unless we store it forever in # some variable. # 2. We want to be idempotent and only install the hook once. if rewrite_hook not in connection.execute_wrappers: # pragma: no branch connection.execute_wrappers.append(rewrite_hook)
def check_variables(app_configs, **kwargs): errors = [] for alias, connection in mysql_connections(): with connection.temporary_connection() as cursor: cursor.execute("""SELECT @@sql_mode, @@innodb_strict_mode, @@character_set_connection""") variables = cursor.fetchone() sql_mode, innodb_strict_mode, character_set_connection = variables modes = set(sql_mode.split(",")) if not (modes & {"STRICT_TRANS_TABLES", "STRICT_ALL_TABLES"}): errors.append(strict_mode_warning(alias)) if not innodb_strict_mode: errors.append(innodb_strict_mode_warning(alias)) if character_set_connection != "utf8mb4": errors.append(utf8mb4_warning(alias)) return errors