biopragmatics / bioregistry

📮 An integrative registry of biological databases, ontologies, and nomenclatures.
https://bioregistry.io
MIT License
116 stars 51 forks source link

Can't construct reference page if slash in identifier #1077

Closed cthoyt closed 6 months ago

cthoyt commented 6 months ago
          I believe this is still/again an issue: look at e.g. the registry page for [CTRI](https://bioregistry.io/registry/ctri) (India Clinical Trials Registry), and click on the example CURIE: https://bioregistry.io/reference/ctri:CTRI/2023/04/052053, at least for me I get an internal server error instead of it resolving.

Originally posted by @kkaris in https://github.com/biopragmatics/bioregistry/issues/31#issuecomment-2030201710

It looks like the issue is inside the template, where starlette isn't happy if there's a slash inside any of the parameters in constructing a path

2024-04-02 08:54:05 ERROR    Exception on /reference/ctri:CTRI/2023/04/052053 [GET]
Traceback (most recent call last):
  File "/Users/cthoyt/.virtualenvs/indra/lib/python3.11/site-packages/flask/app.py", line 2529, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cthoyt/.virtualenvs/indra/lib/python3.11/site-packages/flask/app.py", line 1825, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cthoyt/.virtualenvs/indra/lib/python3.11/site-packages/flask/app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cthoyt/.virtualenvs/indra/lib/python3.11/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cthoyt/dev/bioregistry/src/bioregistry/app/ui.py", line 353, in reference
    return render_template(
           ^^^^^^^^^^^^^^^^
  File "/Users/cthoyt/.virtualenvs/indra/lib/python3.11/site-packages/flask/templating.py", line 147, in render_template
    return _render(app, template, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cthoyt/.virtualenvs/indra/lib/python3.11/site-packages/flask/templating.py", line 130, in _render
    rv = template.render(context)
         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cthoyt/.virtualenvs/indra/lib/python3.11/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/Users/cthoyt/.virtualenvs/indra/lib/python3.11/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/Users/cthoyt/dev/bioregistry/src/bioregistry/app/templates/reference.html", line 2, in top-level template code
    {% import "macros.html" as utils %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cthoyt/dev/bioregistry/src/bioregistry/app/templates/base.html", line 164, in top-level template code
    {% block main %}
  File "/Users/cthoyt/dev/bioregistry/src/bioregistry/app/templates/base.html", line 168, in block 'main'
    {% block container %}{% endblock %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cthoyt/dev/bioregistry/src/bioregistry/app/templates/reference.html", line 26, in block 'container'
    href="{{ fastapi_url_for("get_reference", prefix=prefix, identifier=identifier) }}?format={{ key }}">
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cthoyt/.virtualenvs/indra/lib/python3.11/site-packages/starlette/applications.py", line 116, in url_path_for
    return self.router.url_path_for(__name, **path_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cthoyt/.virtualenvs/indra/lib/python3.11/site-packages/starlette/routing.py", line 643, in url_path_for
    return route.url_path_for(__name, **path_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cthoyt/.virtualenvs/indra/lib/python3.11/site-packages/starlette/routing.py", line 259, in url_path_for
    path, remaining_params = replace_params(
                             ^^^^^^^^^^^^^^^
  File "/Users/cthoyt/.virtualenvs/indra/lib/python3.11/site-packages/starlette/routing.py", line 101, in replace_params
    value = convertor.to_string(value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cthoyt/.virtualenvs/indra/lib/python3.11/site-packages/starlette/convertors.py", line 26, in to_string
    assert "/" not in value, "May not contain path separators"
           ^^^^^^^^^^^^^^^^
AssertionError: May not contain path separators