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

Bump sqlalchemy from 1.4.46 to 2.0.1 #738

Merged
merged 5 commits into from
Apr 5, 2023
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
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pysftp = "~=0.2"
python-dotenv = "~=1.0"
requests = "~=2.28"
slackclient = "~=2.9"
sqlalchemy = "~=1.4"
sqlalchemy = "~=2.0"
lab-share-lib = { git = 'https://github.com/sanger/lab-share-lib.git', ref = 'master', editable = false }

[requires]
Expand Down
96 changes: 52 additions & 44 deletions Pipfile.lock

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

51 changes: 27 additions & 24 deletions setup_test_db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# flake8: noqa
from sqlalchemy import text

import crawler.config.test as config
from crawler.db.mysql import create_mysql_connection_engine

Expand All @@ -11,6 +13,7 @@
create_db = """
CREATE DATABASE IF NOT EXISTS `unified_warehouse_test` /*!40100 DEFAULT CHARACTER SET latin1 */;
"""

drop_table_lh_sample = """
DROP TABLE IF EXISTS `unified_warehouse_test`.`lighthouse_sample`;
"""
Expand Down Expand Up @@ -204,25 +207,25 @@
"""

with sql_engine.connect() as connection:
connection.execute(create_db)
connection.execute(text(create_db))

print("*** Dropping table LIGHTHOUSE SAMPLE ***")
connection.execute(drop_table_lh_sample)
connection.execute(text(drop_table_lh_sample))
print("*** Dropping table STOCK RESOURCE ***")
connection.execute(drop_table_stock_resource)
connection.execute(text(drop_table_stock_resource))
print("*** Dropping table STUDY ***")
connection.execute(drop_table_study)
connection.execute(text(drop_table_study))
print("*** Dropping table SAMPLE ***")
connection.execute(drop_table_sample)
connection.execute(text(drop_table_sample))

print("*** Creating table SAMPLE ***")
connection.execute(create_table_sample)
connection.execute(text(create_table_sample))
print("*** Creating table STUDY ***")
connection.execute(create_table_study)
connection.execute(text(create_table_study))
print("*** Creating table STOCK RESOURCE ***")
connection.execute(create_table_stock_resource)
connection.execute(text(create_table_stock_resource))
print("*** Creating table LIGHTHOUSE SAMPLE ***")
connection.execute(create_table_lh_sample)
connection.execute(text(create_table_lh_sample))

print("Initialising the test MySQL events warehouse database")

Expand Down Expand Up @@ -370,36 +373,36 @@
"""

with sql_engine.connect() as connection:
connection.execute(create_db)
connection.execute(text(create_db))

print("*** Dropping view CHERRYPICKED SAMPLES ***")
connection.execute(drop_view_cherrypicked_samples)
connection.execute(text(drop_view_cherrypicked_samples))
print("*** Dropping table ROLES ***")
connection.execute(drop_table_roles)
connection.execute(text(drop_table_roles))
print("*** Dropping table ROLE TYPES ***")
connection.execute(drop_table_role_types)
connection.execute(text(drop_table_role_types))
print("*** Dropping table EVENTS ***")
connection.execute(drop_table_events)
connection.execute(text(drop_table_events))
print("*** Dropping table EVENT TYPES ***")
connection.execute(drop_table_event_types)
connection.execute(text(drop_table_event_types))
print("*** Dropping table SUBJECT ***")
connection.execute(drop_table_subjects)
connection.execute(text(drop_table_subjects))
print("*** Dropping table SUBJECT TYPES ***")
connection.execute(drop_table_subject_types)
connection.execute(text(drop_table_subject_types))

print("*** Creating table SUBJECT TYPES ***")
connection.execute(create_table_subject_types)
connection.execute(text(create_table_subject_types))
print("*** Creating table SUBJECTS ***")
connection.execute(create_table_subjects)
connection.execute(text(create_table_subjects))
print("*** Creating table EVENT TYPES ***")
connection.execute(create_table_event_types)
connection.execute(text(create_table_event_types))
print("*** Creating table EVENTS ***")
connection.execute(create_table_events)
connection.execute(text(create_table_events))
print("*** Creating table ROLE TYPES ***")
connection.execute(create_table_role_types)
connection.execute(text(create_table_role_types))
print("*** Creating table ROLES ***")
connection.execute(create_table_roles)
connection.execute(text(create_table_roles))
print("*** Creating view CHERRYPICKED SAMPLES ***")
connection.execute(create_cherrypicked_samples_view)
connection.execute(text(create_cherrypicked_samples_view))

print("Done")
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ def delete_sql_engine_tables(engine, tables):


def get_table(sql_engine, table_name):
metadata = MetaData(sql_engine)
metadata.reflect()
metadata = MetaData()
metadata.reflect(sql_engine)
return metadata.tables[table_name]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
from pymongo import ASCENDING
from sqlalchemy import text

from crawler.constants import (
FIELD_LH_SAMPLE_UUID,
Expand Down Expand Up @@ -83,23 +84,23 @@ def test_back_populate_source_plate_uuid_and_sample_uuid_populates_sample_uuid(
viewed_uuids.append(sample[FIELD_LH_SAMPLE_UUID])

# Now we check in mlwh
cursor = query_lighthouse_sample.execute(
"SELECT COUNT(*) FROM lighthouse_sample WHERE plate_barcode = '123' AND lh_sample_uuid IS NOT NULL"
cursor_result = query_lighthouse_sample.execute(
text("SELECT COUNT(*) FROM lighthouse_sample WHERE plate_barcode = '123' AND lh_sample_uuid IS NOT NULL")
)

sample_count = cursor.fetchone()[0]
sample_count = cursor_result.first()[0]
assert sample_count == len(samples_after)

cursor = query_lighthouse_sample.execute(
"SELECT * FROM lighthouse_sample WHERE plate_barcode = '123' AND lh_sample_uuid IS NOT NULL"
cursor_result = query_lighthouse_sample.execute(
text("SELECT * FROM lighthouse_sample WHERE plate_barcode = '123' AND lh_sample_uuid IS NOT NULL")
)

obtained_mlwh_samples = list(cursor.fetchall())
results = list(cursor_result.mappings())
mongo_dict = {}
for sample in samples_after:
mongo_dict[str(sample[FIELD_MONGODB_ID])] = sample[FIELD_LH_SAMPLE_UUID]
mlwh_dict = {}
for mlsample in obtained_mlwh_samples:
for mlsample in results:
mlwh_dict[mlsample[MLWH_MONGODB_ID]] = mlsample[FIELD_LH_SAMPLE_UUID]

for mongo_id in mongo_dict.keys():
Expand Down Expand Up @@ -157,23 +158,23 @@ def test_back_populate_source_plate_uuid_and_sample_uuid_has_source_plate_uuid(
assert sample[FIELD_LH_SOURCE_PLATE_UUID] == source_plate_uuid

# Now we check in mlwh
cursor = query_lighthouse_sample.execute(
"SELECT COUNT(*) FROM lighthouse_sample WHERE lh_source_plate_uuid IS NOT NULL"
cursor_result = query_lighthouse_sample.execute(
text("SELECT COUNT(*) FROM lighthouse_sample WHERE lh_source_plate_uuid IS NOT NULL")
)

sample_count = cursor.fetchone()[0]
sample_count = cursor_result.first()[0]
assert sample_count == len(samples_after)

cursor = query_lighthouse_sample.execute(
"SELECT * FROM lighthouse_sample WHERE lh_source_plate_uuid IS NOT NULL ORDER BY mongodb_id ASC"
cursor_result = query_lighthouse_sample.execute(
text("SELECT * FROM lighthouse_sample WHERE lh_source_plate_uuid IS NOT NULL ORDER BY mongodb_id ASC")
)

obtained_mlwh_samples = list(cursor.fetchall())
results = list(cursor_result.mappings())
mongo_dict = {}
for sample in samples_after:
mongo_dict[str(sample[FIELD_MONGODB_ID])] = sample[FIELD_LH_SOURCE_PLATE_UUID]
mlwh_dict = {}
for mlsample in obtained_mlwh_samples:
for mlsample in results:
mlwh_dict[mlsample[MLWH_MONGODB_ID]] = mlsample[FIELD_LH_SOURCE_PLATE_UUID]

for mongo_id in mongo_dict.keys():
Expand Down
11 changes: 6 additions & 5 deletions tests/migrations/test_reconnect_mlwh_with_mongo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from sqlalchemy import text

from crawler.constants import FIELD_MONGODB_ID, FIELD_PLATE_BARCODE, FIELD_RNA_ID, MLWH_MONGODB_ID, MLWH_RNA_ID
from migrations import reconnect_mlwh_with_mongo
Expand Down Expand Up @@ -35,15 +36,15 @@ def test_reconnect_mlwh_with_mongo_can_connect_with_mlwh(
reconnect_mlwh_with_mongo.run(config, filepath)

# Now we check in mlwh
cursor = query_lighthouse_sample.execute(
"SELECT rna_id, mongodb_id FROM lighthouse_sample WHERE plate_barcode = '123'"
cursor_result = query_lighthouse_sample.execute(
text("SELECT rna_id, mongodb_id FROM lighthouse_sample WHERE plate_barcode = '123'")
)
results = list(cursor_result.mappings())

obtained_mlwh_samples = list(cursor.fetchall())
assert obtained_mlwh_samples[0]["mongodb_id"] == str(samples_in_mongo[0][FIELD_MONGODB_ID])
assert results[0]["mongodb_id"] == str(samples_in_mongo[0][FIELD_MONGODB_ID])

mlwh_dict = {}
for mlsample in obtained_mlwh_samples:
for mlsample in results:
mlwh_dict[mlsample[MLWH_RNA_ID]] = mlsample[MLWH_MONGODB_ID]

mongo_dict = {}
Expand Down