Skip to content

Commit

Permalink
Update FastAPI Safir UWS app parameter dependency
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rra committed Dec 3, 2024
1 parent 23706a1 commit 5d3302a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 %}
2 changes: 1 addition & 1 deletion project_templates/technote_md/testn-000/technote.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion project_templates/technote_rst/testn-000/technote.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 5d3302a

Please sign in to comment.