From 5d3302a564f2a430c03d0dd14cd8461b6a265606 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Tue, 3 Dec 2024 14:15:11 -0800 Subject: [PATCH] Update FastAPI Safir UWS app parameter dependency Safir no longer provides the `uws_post_params_dependency` since it now installs middleware that fixes the case-insensitive parameter key problem by canonicalizing all parameters. Adjust the FastAPI Safir app template accordingly. --- .../example-uws/src/exampleuws/dependencies.py | 16 +++++----------- .../{{cookiecutter.module_name}}/dependencies.py | 16 +++++----------- .../technote_md/testn-000/technote.toml | 2 +- .../technote_rst/testn-000/technote.toml | 2 +- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/project_templates/fastapi_safir_app/example-uws/src/exampleuws/dependencies.py b/project_templates/fastapi_safir_app/example-uws/src/exampleuws/dependencies.py index 006232e..009c66c 100644 --- a/project_templates/fastapi_safir_app/example-uws/src/exampleuws/dependencies.py +++ b/project_templates/fastapi_safir_app/example-uws/src/exampleuws/dependencies.py @@ -3,7 +3,7 @@ from typing import Annotated from fastapi import Depends -from safir.uws import UWSJobParameter, uws_post_params_dependency +from safir.uws import UWSJobParameter __all__ = [ "post_params_dependency", @@ -13,15 +13,9 @@ async def post_params_dependency( *, # Add POST parameters here. All of them should be Form() parameters. - # Use str | None for single-valued attributes and str | list[str] | None - # for parameters that can be given more than one time. - params: Annotated[ - list[UWSJobParameter], Depends(uws_post_params_dependency) - ], + # Use str | None for single-valued attributes and list[str] | None for + # parameters that can be given more than one time. ) -> list[UWSJobParameter]: """Parse POST parameters into job parameters.""" - return [ - p - for p in params - if p.parameter_id in set() # Replace with set of parameter names - ] + params: list[UWSJobParameter] = [] + # Populate params with the values of all form parameters that were set. diff --git a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/dependencies.py b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/dependencies.py index 304d406..422a489 100644 --- a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/dependencies.py +++ b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/dependencies.py @@ -4,7 +4,7 @@ from typing import Annotated from fastapi import Depends -from safir.uws import UWSJobParameter, uws_post_params_dependency +from safir.uws import UWSJobParameter __all__ = [ "post_params_dependency", @@ -14,16 +14,10 @@ async def post_params_dependency( *, # Add POST parameters here. All of them should be Form() parameters. - # Use str | None for single-valued attributes and str | list[str] | None - # for parameters that can be given more than one time. - params: Annotated[ - list[UWSJobParameter], Depends(uws_post_params_dependency) - ], + # Use str | None for single-valued attributes and list[str] | None for + # parameters that can be given more than one time. ) -> list[UWSJobParameter]: """Parse POST parameters into job parameters.""" - return [ - p - for p in params - if p.parameter_id in set() # Replace with set of parameter names - ] + params: list[UWSJobParameter] = [] + # Populate params with the values of all form parameters that were set. {%- endif %} diff --git a/project_templates/technote_md/testn-000/technote.toml b/project_templates/technote_md/testn-000/technote.toml index 726c3c1..6a0edef 100644 --- a/project_templates/technote_md/testn-000/technote.toml +++ b/project_templates/technote_md/testn-000/technote.toml @@ -4,7 +4,7 @@ series_id = "TESTN" canonical_url = "https://testn-000.lsst.io" github_url = "https://github.com/lsst/testn-000" github_default_branch = "main" -date_created = 2024-11-25T22:09:21Z +date_created = 2024-12-03T22:35:26Z organization.name = "Vera C. Rubin Observatory" organization.ror = "https://ror.org/048g3cy84" license.id = "CC-BY-4.0" diff --git a/project_templates/technote_rst/testn-000/technote.toml b/project_templates/technote_rst/testn-000/technote.toml index f6d5ead..a306c9b 100644 --- a/project_templates/technote_rst/testn-000/technote.toml +++ b/project_templates/technote_rst/testn-000/technote.toml @@ -4,7 +4,7 @@ series_id = "TESTN" canonical_url = "https://testn-000.lsst.io" github_url = "https://github.com/lsst/testn-000" github_default_branch = "main" -date_created = 2024-11-25T22:09:21Z +date_created = 2024-12-03T22:35:26Z organization.name = "Vera C. Rubin Observatory" organization.ror = "https://ror.org/048g3cy84" license.id = "CC-BY-4.0"