From b4d0930ca0da8f56dc778b5f59210e319c034864 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Sep 2025 14:24:25 +0000 Subject: [PATCH 1/2] Initial plan From 89d54b55b205046a3bc50f251fa39975e9feb7cb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Sep 2025 14:33:01 +0000 Subject: [PATCH 2/2] Fix SQLAlchemy 2.0 compatibility issues in core modules Co-authored-by: GraemeWatt <11544204+GraemeWatt@users.noreply.github.com> --- hepdata/cli.py | 3 ++- hepdata/ext/opensearch/query_builder.py | 2 +- hepdata/modules/records/utils/data_files.py | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hepdata/cli.py b/hepdata/cli.py index df6aa806b..712b88eea 100644 --- a/hepdata/cli.py +++ b/hepdata/cli.py @@ -269,7 +269,8 @@ def execute(query): """Execute a SQL query via SQLAlchemy Engine.""" print("Executing query: {}".format(query)) if query: - result = db.session.execute(query) + from sqlalchemy import text + result = db.session.execute(text(query)) if result.returns_rows: for i, row in enumerate(result): print('Row {}:'.format(i + 1), row) diff --git a/hepdata/ext/opensearch/query_builder.py b/hepdata/ext/opensearch/query_builder.py index bb928d6bd..dc4b6239c 100644 --- a/hepdata/ext/opensearch/query_builder.py +++ b/hepdata/ext/opensearch/query_builder.py @@ -79,7 +79,7 @@ def parse_query(query_string): def _quote_phrase(phrase): # Match phrases containing a reaction (including "-->") or a doi (word # chars with / in the middle) and quote them - pattern = re.compile("(.*-->.*|[\w\.]+\/[\w\.]+)") + pattern = re.compile(r"(.*-->.*|[\w\.]+\/[\w\.]+)") if '"' not in phrase and pattern.fullmatch(phrase): return f'"{phrase}"' diff --git a/hepdata/modules/records/utils/data_files.py b/hepdata/modules/records/utils/data_files.py index df000032b..f3f8122e1 100644 --- a/hepdata/modules/records/utils/data_files.py +++ b/hepdata/modules/records/utils/data_files.py @@ -29,6 +29,7 @@ from celery import shared_task from flask import current_app from invenio_db import db +from sqlalchemy import text from hepdata.modules.email.utils import create_send_email_task from hepdata.modules.records.utils.common import allowed_file @@ -254,7 +255,7 @@ def _delete_all_orphan_file_resources(): # pragma: no cover # ~196k rows in datafile_identifier - explain analyse on QA takes 92ms # Produces ~300k orphans on QA. result = db.session.execute( - """ + text(""" CREATE TEMP TABLE valid_resource_ids(id INT); LOCK TABLE data_resource_link IN EXCLUSIVE MODE; INSERT INTO valid_resource_ids @@ -270,7 +271,7 @@ def _delete_all_orphan_file_resources(): # pragma: no cover SELECT id from valid_resource_ids WHERE valid_resource_ids.id = dataresource.id ); - """ + """) ) ids_to_delete = [x[0] for x in result]