Skip to content

Commit

Permalink
fix: replace mysqlclient with pymysql (#1949)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolin999 authored Oct 8, 2024
1 parent 6a10e3c commit 9d830bf
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 60 deletions.
5 changes: 3 additions & 2 deletions src/bk-login/bklogin/monitoring/tracing/instrumentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

import logging
from typing import Collection

Expand Down Expand Up @@ -36,11 +37,11 @@ def _instrument(self, **kwargs):
logger.info("otel instructment: django")

if getattr(settings, "OTEL_INSTRUMENT_DB_API", False):
import MySQLdb # noqa
import pymysql

dbapi.wrap_connect(
__name__,
MySQLdb,
pymysql.connect,
"connect",
"mysql",
{"database": "db", "port": "port", "host": "host", "user": "user"},
Expand Down
3 changes: 3 additions & 0 deletions src/bk-login/bklogin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
from urllib.parse import urlparse

import environ
import pymysql
import urllib3
from django.utils.encoding import force_bytes

pymysql.install_as_MySQLdb()

# environ
env = environ.Env()
# load environment variables from .env file
Expand Down
63 changes: 38 additions & 25 deletions src/bk-login/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/bk-login/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ priority = "default"
[tool.poetry.dependencies]
python = ">=3.10,<3.11"
django = "3.2.25"
mysqlclient = "2.2.4"
pymysql = "1.1.1"
requests = "2.31.0"
gunicorn = "21.2.0"
gevent = "23.9.1"
Expand Down Expand Up @@ -46,6 +46,7 @@ types-requests = "^2.31.0.2"
pytest = "^7.4.2"
pytest-django = "^4.5.2"
import-linter = "^1.11.1"
types-pymysql = "^1.1.0.20240524"

[tool.mypy]
ignore_missing_imports = true
Expand Down
2 changes: 1 addition & 1 deletion src/bk-login/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ gunicorn==21.2.0 ; python_version >= "3.10" and python_version < "3.11"
idna==3.7 ; python_version >= "3.10" and python_version < "3.11"
importlib-metadata==7.1.0 ; python_version >= "3.10" and python_version < "3.11"
markupsafe==2.1.5 ; python_version >= "3.10" and python_version < "3.11"
mysqlclient==2.2.4 ; python_version >= "3.10" and python_version < "3.11"
opentelemetry-api==1.25.0 ; python_version >= "3.10" and python_version < "3.11"
opentelemetry-exporter-otlp-proto-common==1.25.0 ; python_version >= "3.10" and python_version < "3.11"
opentelemetry-exporter-otlp-proto-grpc==1.25.0 ; python_version >= "3.10" and python_version < "3.11"
Expand All @@ -55,6 +54,7 @@ pycryptodomex==3.20.0 ; python_version >= "3.10" and python_version < "3.11"
pydantic-core==2.6.3 ; python_version >= "3.10" and python_version < "3.11"
pydantic==2.3.0 ; python_version >= "3.10" and python_version < "3.11"
pyjwt==2.8.0 ; python_version >= "3.10" and python_version < "3.11"
pymysql==1.1.1 ; python_version >= "3.10" and python_version < "3.11"
python-editor==1.0.4 ; python_version >= "3.10" and python_version < "3.11"
python-json-logger==2.0.7 ; python_version >= "3.10" and python_version < "3.11"
pytz==2024.1 ; python_version >= "3.10" and python_version < "3.11"
Expand Down
3 changes: 2 additions & 1 deletion src/bk-login/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ iniconfig==2.0.0 ; python_version >= "3.10" and python_version < "3.11"
markupsafe==2.1.5 ; python_version >= "3.10" and python_version < "3.11"
mypy-extensions==1.0.0 ; python_version >= "3.10" and python_version < "3.11"
mypy==1.11.0 ; python_version >= "3.10" and python_version < "3.11"
mysqlclient==2.2.4 ; python_version >= "3.10" and python_version < "3.11"
opentelemetry-api==1.25.0 ; python_version >= "3.10" and python_version < "3.11"
opentelemetry-exporter-otlp-proto-common==1.25.0 ; python_version >= "3.10" and python_version < "3.11"
opentelemetry-exporter-otlp-proto-grpc==1.25.0 ; python_version >= "3.10" and python_version < "3.11"
Expand Down Expand Up @@ -62,6 +61,7 @@ pycryptodomex==3.20.0 ; python_version >= "3.10" and python_version < "3.11"
pydantic-core==2.6.3 ; python_version >= "3.10" and python_version < "3.11"
pydantic==2.3.0 ; python_version >= "3.10" and python_version < "3.11"
pyjwt==2.8.0 ; python_version >= "3.10" and python_version < "3.11"
pymysql==1.1.1 ; python_version >= "3.10" and python_version < "3.11"
pytest-django==4.8.0 ; python_version >= "3.10" and python_version < "3.11"
pytest==7.4.4 ; python_version >= "3.10" and python_version < "3.11"
python-editor==1.0.4 ; python_version >= "3.10" and python_version < "3.11"
Expand All @@ -77,6 +77,7 @@ sqlparse==0.5.1 ; python_version >= "3.10" and python_version < "3.11"
toml==0.10.2 ; python_version >= "3.10" and python_version < "3.11"
tomli==2.0.1 ; python_version >= "3.10" and python_version < "3.11"
tongsuopy-crayon==1.0.2b6 ; python_version >= "3.10" and python_version < "3.11"
types-pymysql==1.1.0.20240524 ; python_version >= "3.10" and python_version < "3.11"
types-requests==2.32.0.20240712 ; python_version >= "3.10" and python_version < "3.11"
typing-extensions==4.12.2 ; python_version >= "3.10" and python_version < "3.11"
urllib3==2.2.2 ; python_version >= "3.10" and python_version < "3.11"
Expand Down
5 changes: 3 additions & 2 deletions src/bk-user/bkuser/monitoring/tracing/instrumentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

import logging
from typing import Collection

Expand Down Expand Up @@ -42,11 +43,11 @@ def _instrument(self, **kwargs):
logger.info("otel instructment: celery")

if getattr(settings, "OTEL_INSTRUMENT_DB_API", False):
import MySQLdb # noqa
import pymysql

dbapi.wrap_connect(
__name__,
MySQLdb,
pymysql.connect,
"connect",
"mysql",
{"database": "db", "port": "port", "host": "host", "user": "user"},
Expand Down
3 changes: 3 additions & 0 deletions src/bk-user/bkuser/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
from urllib.parse import urlparse

import environ
import pymysql
import urllib3
from celery.schedules import crontab
from django.utils.encoding import force_bytes

pymysql.install_as_MySQLdb()

# environ
env = environ.Env()
# load environment variables from .env file
Expand Down
63 changes: 38 additions & 25 deletions src/bk-user/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/bk-user/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ djangorestframework = "3.14.0"
celery = "5.3.1"
django-celery-beat = "2.5.0"
django-celery-results = "2.5.1"
mysqlclient = "2.2.4"
pymysql = "1.1.1"
requests = "2.31.0"
gunicorn = "20.1.0"
gevent = "24.2.1"
Expand Down Expand Up @@ -62,6 +62,7 @@ pytest-django = "^4.5.2"
types-pytz = "^2023.3.0.0"
import-linter = "^1.11.1"
types-redis = "^4.6.0.20240806"
types-pymysql = "^1.1.0.20240524"

[tool.mypy]
ignore_missing_imports = true
Expand Down
2 changes: 1 addition & 1 deletion src/bk-user/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ inflection==0.5.1 ; python_version >= "3.10" and python_version < "3.11"
jsonref==1.1.0 ; python_version >= "3.10" and python_version < "3.11"
kombu==5.4.0 ; python_version >= "3.10" and python_version < "3.11"
markupsafe==2.1.5 ; python_version >= "3.10" and python_version < "3.11"
mysqlclient==2.2.4 ; python_version >= "3.10" and python_version < "3.11"
openpyxl==3.1.2 ; python_version >= "3.10" and python_version < "3.11"
opentelemetry-api==1.24.0 ; python_version >= "3.10" and python_version < "3.11"
opentelemetry-exporter-otlp-proto-common==1.24.0 ; python_version >= "3.10" and python_version < "3.11"
Expand Down Expand Up @@ -79,6 +78,7 @@ pycryptodomex==3.20.0 ; python_version >= "3.10" and python_version < "3.11"
pydantic-core==2.4.0 ; python_version >= "3.10" and python_version < "3.11"
pydantic==2.1.1 ; python_version >= "3.10" and python_version < "3.11"
pyjwt==2.9.0 ; python_version >= "3.10" and python_version < "3.11"
pymysql==1.1.1 ; python_version >= "3.10" and python_version < "3.11"
python-crontab==3.2.0 ; python_version >= "3.10" and python_version < "3.11"
python-dateutil==2.9.0.post0 ; python_version >= "3.10" and python_version < "3.11"
python-editor==1.0.4 ; python_version >= "3.10" and python_version < "3.11"
Expand Down
3 changes: 2 additions & 1 deletion src/bk-user/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ kombu==5.4.0 ; python_version >= "3.10" and python_version < "3.11"
markupsafe==2.1.5 ; python_version >= "3.10" and python_version < "3.11"
mypy-extensions==1.0.0 ; python_version >= "3.10" and python_version < "3.11"
mypy==1.10.1 ; python_version >= "3.10" and python_version < "3.11"
mysqlclient==2.2.4 ; python_version >= "3.10" and python_version < "3.11"
openpyxl==3.1.2 ; python_version >= "3.10" and python_version < "3.11"
opentelemetry-api==1.24.0 ; python_version >= "3.10" and python_version < "3.11"
opentelemetry-exporter-otlp-proto-common==1.24.0 ; python_version >= "3.10" and python_version < "3.11"
Expand Down Expand Up @@ -86,6 +85,7 @@ pycryptodomex==3.20.0 ; python_version >= "3.10" and python_version < "3.11"
pydantic-core==2.4.0 ; python_version >= "3.10" and python_version < "3.11"
pydantic==2.1.1 ; python_version >= "3.10" and python_version < "3.11"
pyjwt==2.9.0 ; python_version >= "3.10" and python_version < "3.11"
pymysql==1.1.1 ; python_version >= "3.10" and python_version < "3.11"
pytest-django==4.8.0 ; python_version >= "3.10" and python_version < "3.11"
pytest==7.4.4 ; python_version >= "3.10" and python_version < "3.11"
python-crontab==3.2.0 ; python_version >= "3.10" and python_version < "3.11"
Expand All @@ -106,6 +106,7 @@ toml==0.10.2 ; python_version >= "3.10" and python_version < "3.11"
tomli==2.0.1 ; python_version >= "3.10" and python_version < "3.11"
tongsuopy-crayon==1.0.2b6 ; python_version >= "3.10" and python_version < "3.11"
types-cffi==1.16.0.20240331 ; python_version >= "3.10" and python_version < "3.11"
types-pymysql==1.1.0.20240524 ; python_version >= "3.10" and python_version < "3.11"
types-pyopenssl==24.1.0.20240722 ; python_version >= "3.10" and python_version < "3.11"
types-pytz==2023.4.0.20240130 ; python_version >= "3.10" and python_version < "3.11"
types-redis==4.6.0.20240806 ; python_version >= "3.10" and python_version < "3.11"
Expand Down

0 comments on commit 9d830bf

Please sign in to comment.