Skip to content

Commit

Permalink
fix: SyntaxWarning: invalid escape sequence '\:'
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed Oct 10, 2024
1 parent f1bd532 commit 1e49977
Showing 1 changed file with 7 additions and 2 deletions.
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

0 comments on commit 1e49977

Please sign in to comment.