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

Bugfix/check mariadb version #679

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2c4e7de
Add test to verify charset, collation and engines match
jmcarson Jul 29, 2024
cae3673
fix formatting
jmcarson Jul 29, 2024
e3b4636
Try setting charset and collation
jmcarson Jul 30, 2024
cea89a7
try passing charset options another way
jmcarson Jul 30, 2024
2731c79
Stop trying to set charset within ci, instead set in django config
jmcarson Jul 30, 2024
3ab13f6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 30, 2024
78c8e71
log db options to be sure they are being set correctly
jmcarson Jul 30, 2024
5319db7
Add charset to db url
jmcarson Jul 30, 2024
e9ca0f1
Try to run sqlite last in case starting mariadb during sqlite run is …
jmcarson Jul 30, 2024
1fd717f
Stop using mysql schema
jmcarson Jul 30, 2024
911da19
Add a step to print db options
amstilp Jul 30, 2024
ca7b785
Add step to debug on failure
amstilp Jul 30, 2024
2f2afeb
Move debugging action to after db options step
amstilp Jul 30, 2024
5ef7c59
Fix printing of mysql options
amstilp Jul 30, 2024
8144b10
Try specifying default-character-set when starting mariadb server
amstilp Jul 30, 2024
4c40b22
Set up a tmate session for interactive debugging
amstilp Jul 30, 2024
d4aea93
Remove default charset from mysql options
amstilp Jul 30, 2024
809f98e
Try setting TEST database charset and collation
amstilp Jul 30, 2024
2408dd2
Remove tmate CI step
amstilp Jul 30, 2024
13d6256
Fix how test database settings are set
amstilp Jul 30, 2024
9e6e8c3
Add phenotype inventory test to see if it fails
amstilp Jul 30, 2024
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
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
matrix:
python-version: [3.8]
backend: ["sqlite", "mariadb"]
backend: ["mariadb", "sqlite"]
mariadb-version: ["10.4"]
include:
- python-version: "3.10" # Future ubuntu 22.04 upgrade.
Expand Down Expand Up @@ -53,10 +53,14 @@ jobs:
env:
PYTEST_ADDOPTS: "--maxfail=20" # Stop testing after too many failures.
# Conditionally set the database url based on the backend.
DATABASE_URL: ${{ matrix.backend == 'sqlite' && 'sqlite:///db.sqlite3' || 'mysql://root:[email protected]:3306/mysql' }}
DATABASE_URL: ${{ matrix.backend == 'sqlite' && 'sqlite:///db.sqlite3' || 'mysql://root:[email protected]:3306/test_db?charset=utf8mb4' }}

steps:

- name: Print db options
run: |
mysql --verbose --help

- name: Checkout Code Repository
uses: actions/checkout@v4

Expand Down
11 changes: 11 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@
DATABASES = {
"default": env.db("DATABASE_URL", default="sqlite:///primed.db"),
}

if DATABASES["default"]["ENGINE"] == "django.db.backends.mysql":
DATABASES["default"]["TEST"] = {
"CHARSET": "utf8mb4",
"COLLATION": "utf8mb4_general_ci", # or other collation
}
DATABASES["default"]["OPTIONS"] = {
"charset": "utf8mb4", # or other charset
"collation": "utf8mb4_general_ci", # or other collation
}

# DATABASES["default"]["ATOMIC_REQUESTS"] = True
# # https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
Expand Down
71 changes: 71 additions & 0 deletions primed/primed_anvil/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,3 +789,74 @@ def test_multiple_workspace_types_separate_studies(self):
self.assertEqual(res["test-bp-cdsa/test-ws-cdsa"], "TEST 2")
self.assertIn("test-bp-open/test-ws-open", res)
self.assertEqual(res["test-bp-open/test-ws-open"], "TEST 3")

def test_non_consecutive_grouping(self):
"""Studies are grouped even if workspaces are listed non-consecutively."""
# This replicates an issue seen in prod:
# 1) there are multiple workspaces for the same set of studies
# 2) objects are created in a specific order with specific alphabetizing.
# The difference in behavior between sqlite and mariadb is likely due to different ordering
# when the queryset results are returned, so debugging is tricky.
study_1 = StudyFactory.create(short_name="TEST_2")
study_2 = StudyFactory.create(short_name="TEST_1")
study_accession_1 = dbGaPStudyAccessionFactory.create(dbgap_phs=964, studies=[study_1, study_2])
study_accession_2 = dbGaPStudyAccessionFactory.create(dbgap_phs=286, studies=[study_2])
# Two workspaces associated with study_accession_1 (with two studies)
workspace_1_a = dbGaPWorkspaceFactory.create(
workspace__billing_project__name="test-b",
workspace__name="test-a-b_c3",
dbgap_study_accession=study_accession_1,
)
WorkspaceGroupSharingFactory.create(workspace=workspace_1_a.workspace, group=self.primed_all_group)
workspace_2_a = dbGaPWorkspaceFactory.create(
workspace__billing_project__name="test-a",
workspace__name="test-a_c3",
dbgap_study_accession=study_accession_2,
)
WorkspaceGroupSharingFactory.create(workspace=workspace_2_a.workspace, group=self.primed_all_group)
workspace_2_b = dbGaPWorkspaceFactory.create(
workspace__billing_project__name="test-a",
workspace__name="test-a_c4",
dbgap_study_accession=study_accession_2,
)
WorkspaceGroupSharingFactory.create(workspace=workspace_2_b.workspace, group=self.primed_all_group)
workspace_2_c = dbGaPWorkspaceFactory.create(
workspace__billing_project__name="test-a",
workspace__name="test-a_c2",
dbgap_study_accession=study_accession_2,
)
WorkspaceGroupSharingFactory.create(workspace=workspace_2_c.workspace, group=self.primed_all_group)
workspace_2_d = dbGaPWorkspaceFactory.create(
workspace__billing_project__name="test-a",
workspace__name="test-a_c1",
dbgap_study_accession=study_accession_2,
)
WorkspaceGroupSharingFactory.create(workspace=workspace_2_d.workspace, group=self.primed_all_group)
workspace_1_b = dbGaPWorkspaceFactory.create(
workspace__billing_project__name="test-b",
workspace__name="test-a-b_c4",
dbgap_study_accession=study_accession_1,
)
WorkspaceGroupSharingFactory.create(workspace=workspace_1_b.workspace, group=self.primed_all_group)
workspace_1_c = dbGaPWorkspaceFactory.create(
workspace__billing_project__name="test-b",
workspace__name="test-a-b_c1",
dbgap_study_accession=study_accession_1,
)
WorkspaceGroupSharingFactory.create(workspace=workspace_1_c.workspace, group=self.primed_all_group)
workspace_1_d = dbGaPWorkspaceFactory.create(
workspace__billing_project__name="test-b",
workspace__name="test-a-b_c2",
dbgap_study_accession=study_accession_1,
)
WorkspaceGroupSharingFactory.create(workspace=workspace_1_d.workspace, group=self.primed_all_group)
res = helpers.get_workspaces_for_phenotype_inventory()
self.assertEqual(len(res), 8)
self.assertEqual(res["test-b/test-a-b_c1"], "TEST_1, TEST_2")
self.assertEqual(res["test-b/test-a-b_c2"], "TEST_1, TEST_2")
self.assertEqual(res["test-b/test-a-b_c3"], "TEST_1, TEST_2")
self.assertEqual(res["test-b/test-a-b_c4"], "TEST_1, TEST_2")
self.assertEqual(res["test-a/test-a_c1"], "TEST_1")
self.assertEqual(res["test-a/test-a_c2"], "TEST_1")
self.assertEqual(res["test-a/test-a_c3"], "TEST_1")
self.assertEqual(res["test-a/test-a_c4"], "TEST_1")
Empty file added primed/tests/__init__.py
Empty file.
42 changes: 42 additions & 0 deletions primed/tests/test_db_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# test_db_settings.py
import pytest
from django.conf import settings
from django.db import connection


@pytest.mark.django_db
def test_character_set_and_storage_engine():
with connection.cursor() as cursor:
if settings.DATABASES["default"]["ENGINE"] == "django.db.backends.mysql":
print("Database options: {}".format(settings.DATABASES["default"].get("OPTIONS")))
# For MariaDB/MySQL
cursor.execute("SHOW VARIABLES LIKE 'character_set_server';")
charset = cursor.fetchone()
print(f"Character set: {charset[1]}")

cursor.execute("SHOW VARIABLES LIKE 'collation_server';")
collation = cursor.fetchone()
print(f"Collation: {collation[1]}")

cursor.execute("SHOW TABLE STATUS;")
tables = cursor.fetchall()
for table in tables:
print(f"Table: {table[0]}, Engine: {table[1]}")
assert table[1] == "InnoDB"

assert charset[1] == "utf8mb4"
assert collation[1] == "utf8mb4_general_ci"

elif settings.DATABASES["default"]["ENGINE"] == "django.db.backends.sqlite3":
# For SQLite
cursor.execute("PRAGMA encoding;")
charset = cursor.fetchone()
print(f"Character set: {charset[0]}")

cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
for table in tables:
print(f"Table: {table[0]}, Engine: SQLite")

# SQLite always uses UTF-8 encoding
assert charset[0].lower() == "utf-8"
Loading