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

Support multivalued UWS parameters #24

Merged
merged 2 commits into from
Sep 16, 2024
Merged

Conversation

rra
Copy link
Contributor

@rra rra commented Aug 20, 2024

Support multivalued UWS parameters

Some UWS services (SODA, for example) have multivalued job parameters. The parameter may be specified repeatedly with different values. pydantic-xml supports this and produces a model element that holds a list of Parameters, but it previously was not supported by vo-models because the overridden __init__ method didn't know how to handle lists.

Add support to Parameters.__init__ to first flatten all of the input values into a simple list, regardless of which attribute pydantic-xml thought they corresponded to, and then construct a dict based on id values as before, but create a list of Parameter objects if we see the same id more than once. Document that multi-valued parameters should be declared as MultiValuedParameter instead of list[Parameter], which adds a validator that ensures that the parameters are always converted to a list.

Add a test case for multivalued attributes and for correctly parsing parameters given out of order in XML.

Fixes #21

@rra
Copy link
Contributor Author

rra commented Aug 21, 2024

This approach doesn't work in cases where the model attribute is declared as a list but received one element. I'm trying to figure out if there's a better approach that uses more type introspection.

@rra rra marked this pull request as draft August 21, 2024 14:59
Some UWS services (SODA, for example) have multivalued job parameters.
The parameter may be specified repeatedly with different values.
pydantic-xml supports this and produces a model element that holds
a list of Parameters, but it previously was not supported by vo-models
because the overridden `__init__` method didn't know how to handle
lists.

Add support to `Parameters.__init__` to first flatten all of the
input values into a simple list, regardless of which attribute
pydantic-xml thought they corresponded to, and then construct a dict
based on id values as before, but create a list of `Parameter` objects
if we see the same id more than once. Document that multi-valued
parameters should be declared as `MultiValuedParameter` instead of
`list[Parameter]`, which adds a validator that ensures that the
parameters are always converted to a list.

Add a test case for multivalued attributes and for correctly parsing
parameters given out of order in XML.

Fixes spacetelescope#21
@rra rra marked this pull request as ready for review August 21, 2024 19:35
@rra
Copy link
Contributor Author

rra commented Aug 21, 2024

I tried a few ways to fix this, but the easiest is to add a validator to the multi-valued fields. This adds a new data type that makes it easy to do that, and updates the documentation accordingly.

@jwfraustro
Copy link
Collaborator

Thank you for looking into this, and I apologize for not taking a look at this sooner. The Parameters element in the UWS specification have been a thorn in my side for a long time when working with this and I have a sneaking suspicion they will remain so.

I'll take a look at this today-- everything here seems like great work in handling this case.

@jwfraustro jwfraustro merged commit 5ead16e into spacetelescope:main Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parameters support for multi-valued parameters
2 participants