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

fix: SyntaxWarning: invalid escape sequence '\:' #2878

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions invenio_app_rdm/records_ui/views/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright (C) 2019-2024 CERN.
# Copyright (C) 2019-2020 Northwestern University.
# Copyright (C) 2021 TU Wien.
# Copyright (C) 2024 Graz University of Technology.
#
# Invenio App RDM is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -183,9 +184,13 @@ def custom_fields_search(field, field_value, field_cfg=None):
if not locale:
locale = current_app.config.get("BABEL_DEFAULT_LOCALE", "en")
# example: cern:experiments.title.en
namespace_string = "\:".join(namespace_array) + f".{localised_title}.{locale}"
# the \ is necessary for the lucene syntax but produces a SyntaxWarning.
# The r marks the string as raw and prevents the warning
# https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences
namespace_string = r"\:".join(namespace_array) + f".{localised_title}.{locale}"
else:
namespace_string = "\:".join(namespace_array)
namespace_string = r"\:".join(namespace_array)

return url_for(
"invenio_search_ui.search", q=f"custom_fields.{namespace_string}:{field_value}"
)
Expand Down
Loading