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

url_prefix (and others): Cannot set empty environmnent variable default in config.yml #1816

Open
SarahG-579462 opened this issue Sep 20, 2024 · 0 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@SarahG-579462
Copy link

Description

It's not possible to set an environment variable such as url_prefix: ${PYGEOAPI_PREFIX:-} such that, if PYGEOAPI_PREFIX is undefined, no url_prefix is set.

I've tried ${PYGEOAPI_PREFIX:-""}, to no avail (url becomes /""/etc).

Steps to Reproduce

add url_prefix: ${PYGEOAPI_PREFIX:-} to the server api_rules in config.yml

Expected behavior
If PYGEOAPI_PREFIX is set, use this value. If it is not set, do not use a url_prefix

Screenshots/Tracebacks
If applicable, add screenshots to help explain your problem.

backend-1  |   File "/opt/conda/envs/backend/lib/python3.11/site-packages/pygeoapi/starlette_app.py", line 86, in <module>
backend-1  |     api_ = API(CONFIG, OPENAPI)
backend-1  |            ^^^^^^^^^^^^^^^^^^^^
backend-1  |   File "/opt/conda/envs/backend/lib/python3.11/site-packages/pygeoapi/api/__init__.py", line 658, in __init__
backend-1  |     self.base_url = get_base_url(self.config)
backend-1  |                     ^^^^^^^^^^^^^^^^^^^^^^^^^
backend-1  |   File "/opt/conda/envs/backend/lib/python3.11/site-packages/pygeoapi/util.py", line 216, in get_base_url
backend-1  |     return url_join(config['server']['url'], rules.get_url_prefix())
backend-1  |                                              ^^^^^^^^^^^^^^^^^^^^^^
backend-1  |   File "/opt/conda/envs/backend/lib/python3.11/site-packages/pygeoapi/models/config.py", line 95, in get_url_prefix
backend-1  |     prefix = self.url_prefix.format(
backend-1  |              ^^^^^^^^^^^^^^^^^^^^^^^
backend-1  | KeyError: 'PYGEOAPI_PREFIX'

Environment

  • OS:
  • Python version:
  • pygeoapi version:

Additional context

It seems like an issue in the yaml parsing,

r'.*?\$\{(?P<varname>\w+)(:-(?P<default>[^}]+))?\}')

the regex r'.*?\$\{(?P<varname>\w+)(:-(?P<default>[^}]+))?\}' could be changed to r'.*?\$\{(?P<varname>\w+)(:-(?P<default>[^}]*))?\}'

@SarahG-579462 SarahG-579462 added the bug Something isn't working label Sep 20, 2024
@tomkralidis tomkralidis added this to the 0.19.0 milestone Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants