diff --git a/hepdata/cli.py b/hepdata/cli.py index df6aa806..712b88ee 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 bb928d6b..dc4b6239 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 df000032..f3f8122e 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]