Skip to content

Commit

Permalink
Merge pull request #1134 from wklken/fix_mysql_patch
Browse files Browse the repository at this point in the history
  • Loading branch information
wklken authored Nov 29, 2024
2 parents c12fefd + 588efd4 commit b1cba04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/dashboard/apigateway/apigateway/conf/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions src/dashboard/apigateway/apigateway/conf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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)

0 comments on commit b1cba04

Please sign in to comment.