Skip to content

CI: Update Django test workflow #610

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

Merged
merged 15 commits into from
May 18, 2023
32 changes: 20 additions & 12 deletions .github/workflows/django.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ name: Django compat test

on:
push:
pull_request:

jobs:
build:
name: "Run Django LTS test suite"
runs-on: ubuntu-latest
env:
PIP_NO_PYTHON_VERSION_WARNING: 1
PIP_DISABLE_PIP_VERSION_CHECK: 1
DJANGO_VERSION: "3.2.19"
steps:
- name: Start MySQL
run: |
sudo systemctl start mysql.service
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot -proot mysql
mysql -uroot -proot -e "set global innodb_flush_log_at_trx_commit=0;"
mysql -uroot -proot -e "CREATE USER 'scott'@'%' IDENTIFIED BY 'tiger'; GRANT ALL ON *.* TO scott;"
mysql -uroot -proot -e "CREATE DATABASE django_default; CREATE DATABASE django_other;"

Expand All @@ -19,27 +26,28 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
# https://www.mail-archive.com/django-updates@googlegroups.com/msg209056.html
python-version: "3.11"
# Django 3.2.9+ supports Python 3.10
# https://docs.djangoproject.com/ja/3.2/releases/3.2/
python-version: "3.10"
cache: "pip"
cache-dependency-path: "ci/django-requirements.txt"

- name: Install mysqlclient
env:
PIP_NO_PYTHON_VERSION_WARNING: 1
PIP_DISABLE_PIP_VERSION_CHECK: 1
run: |
pip install -r requirements.txt
#pip install -r requirements.txt
#pip install mysqlclient # Use stable version
pip install .
# pip install mysqlclient # Use stable version

- name: Run Django test
env:
DJANGO_VERSION: "3.2.19"
- name: Setup Django
run: |
sudo apt-get install libmemcached-dev
wget https://github.com/django/django/archive/${DJANGO_VERSION}.tar.gz
tar xf ${DJANGO_VERSION}.tar.gz
cp ci/test_mysql.py django-${DJANGO_VERSION}/tests/
cd django-${DJANGO_VERSION}
pip install . -r tests/requirements/py3.txt

- name: Run Django test
run: |
cd django-${DJANGO_VERSION}/tests/
pip install ..
pip install -r requirements/py3.txt
PYTHONPATH=.. python3 ./runtests.py --settings=test_mysql
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ clean:

.PHONY: check
check:
ruff .
black *.py src
ruff *.py src ci
black *.py src ci
6 changes: 4 additions & 2 deletions ci/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
"HOST": "127.0.0.1",
"USER": "scott",
"PASSWORD": "tiger",
"TEST": {"CHARSET": "utf8mb4", "COLLATION": "utf8mb4_general_ci"},
"TEST": {"CHARSET": "utf8mb3", "COLLATION": "utf8mb3_general_ci"},
},
"other": {
"ENGINE": "django.db.backends.mysql",
"NAME": "django_other",
"HOST": "127.0.0.1",
"USER": "scott",
"PASSWORD": "tiger",
"TEST": {"CHARSET": "utf8mb4", "COLLATION": "utf8mb4_general_ci"},
"TEST": {"CHARSET": "utf8mb3", "COLLATION": "utf8mb3_general_ci"},
},
}

Expand All @@ -37,3 +37,5 @@
PASSWORD_HASHERS = [
"django.contrib.auth.hashers.MD5PasswordHasher",
]

DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
10 changes: 7 additions & 3 deletions src/MySQLdb/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, connection):
self.connection = connection
self.description = None
self.description_flags = None
self.rowcount = -1
self.rowcount = 0
self.arraysize = 1
self._executed = None

Expand All @@ -78,8 +78,10 @@ def __init__(self, connection):
def _discard(self):
self.description = None
self.description_flags = None
self.rowcount = -1
self.lastrowid = None
# Django uses some member after __exit__.
# So we keep rowcount and lastrowid here. They are cleared in Cursor._query().
# self.rowcount = 0
# self.lastrowid = None
self._rows = None
self.rownumber = None

Expand Down Expand Up @@ -323,6 +325,8 @@ def callproc(self, procname, args=()):
def _query(self, q):
db = self._get_db()
self._result = None
self.rowcount = None
self.lastrowid = None
db.query(q)
self._do_get_result(db)
self._post_get_result()
Expand Down