From 588efd49b3be8c07079d62a7ebf4094d45b08809 Mon Sep 17 00:00:00 2001 From: wklken Date: Fri, 29 Nov 2024 11:51:15 +0800 Subject: [PATCH] fix(default.py): patch django 4.2 to support mysql 5.7 --- src/dashboard/apigateway/apigateway/conf/default.py | 7 ++++++- src/dashboard/apigateway/apigateway/conf/utils.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/dashboard/apigateway/apigateway/conf/default.py b/src/dashboard/apigateway/apigateway/conf/default.py index fd7346774..d9336a656 100644 --- a/src/dashboard/apigateway/apigateway/conf/default.py +++ b/src/dashboard/apigateway/apigateway/conf/default.py @@ -24,18 +24,23 @@ import urllib3 from celery.schedules import crontab from django.core.exceptions import ImproperlyConfigured +from django.db.backends.mysql.features import DatabaseFeatures from django.utils.encoding import force_bytes from apigateway.common.env import Env from apigateway.conf.celery_conf import * # noqa from apigateway.conf.celery_conf import CELERY_BEAT_SCHEDULE from apigateway.conf.log_utils import build_logging_config -from apigateway.conf.utils import get_default_keepalive_options +from apigateway.conf.utils import PatchFeatures, get_default_keepalive_options pymysql.install_as_MySQLdb() # Patch version info to force pass Django client check pymysql.version_info = 1, 4, 6, "final", 0 +# 目前 Django 仅是对 5.7 做了软性的不兼容改动,在没有使用 8.0 特异的功能时,对 5.7 版本的使用无影响 +DatabaseFeatures.minimum_database_version = PatchFeatures.minimum_database_version + + # Patch the SSL module for compatibility with legacy CA credentials. # https://stackoverflow.com/questions/72479812/how-to-change-tweak-python-3-10-default-ssl-settings-for-requests-sslv3-alert urllib3.util.ssl_.DEFAULT_CIPHERS = "ALL:@SECLEVEL=1" diff --git a/src/dashboard/apigateway/apigateway/conf/utils.py b/src/dashboard/apigateway/apigateway/conf/utils.py index b00033d0b..e40cd98f9 100644 --- a/src/dashboard/apigateway/apigateway/conf/utils.py +++ b/src/dashboard/apigateway/apigateway/conf/utils.py @@ -19,6 +19,8 @@ import socket from typing import Optional +from django.utils.functional import cached_property + def get_default_keepalive_options() -> Optional[dict]: """Mac OS's socket module does not has below attrs, return empty options instead""" @@ -30,3 +32,11 @@ def get_default_keepalive_options() -> Optional[dict]: } except AttributeError: return None + + +class PatchFeatures: + @cached_property + def minimum_database_version(self): + if self.connection.mysql_is_mariadb: + return (10, 4) + return (5, 7)