Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(default.py): patch django 4.2 to support mysql 5.7 #1133

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)