Skip to content
Draft
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
3 changes: 2 additions & 1 deletion hepdata/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion hepdata/ext/opensearch/query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"'
Expand Down
5 changes: 3 additions & 2 deletions hepdata/modules/records/utils/data_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down