geopython / pywps

PyWPS is an implementation of the Web Processing Service standard from the Open Geospatial Consortium. PyWPS is written in Python.
https://pywps.org
MIT License
178 stars 117 forks source link

Input with optional `reference` in `UoM` raises `KeyError` if not a OGC unit #685

Closed fmigneault closed 1 year ago

fmigneault commented 1 year ago

Following definition is problematic: https://github.com/geopython/pywps/blob/6293f3d5f69470b252863a838160f6959c83e5cf/pywps/inout/basic.py#L79-L80

This code makes it such that a definition such as the following will raise:

from pywps.inout import LiteralInput

# explicit None reference
LiteralInput.from_json({"identifier": "test", "uoms": [{"uom": "seconds", "reference": None}]})
Traceback (most recent call last):
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3526, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-13-50a089990430>", line 1, in <module>
    LiteralInput.from_json({"identifier": "test", "uoms": [{"uom": "seconds", "reference": None}]})
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/pywps/inout/inputs.py", line 353, in from_json
    json_input_copy['uoms'] = [
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/pywps/inout/inputs.py", line 354, in <listcomp>
    basic.UOM(uom['uom'], uom['reference'])
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/pywps/inout/basic.py", line 73, in __init__
    self.reference = OGCUNIT[self.uom]
KeyError: 'seconds'
# omitting the reference
LiteralInput.from_json({"identifier": "test", "uoms": [{"uom": "seconds"}]})
Traceback (most recent call last):
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3526, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-14-17dec5faa665>", line 1, in <module>
    LiteralInput.from_json({"identifier": "test", "uoms": [{"uom": "seconds"}]})
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/pywps/inout/inputs.py", line 353, in from_json
    json_input_copy['uoms'] = [
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/pywps/inout/inputs.py", line 354, in <listcomp>
    basic.UOM(uom['uom'], uom['reference'])
KeyError: 'reference'

According to ows:DomainMetadataType in https://schemas.opengis.net/ows/1.1.0/owsDomainType.xsd (type of ows:UOM), the reference is optional. It is not possible to define such unit without an explicit URI provided as reference at the moment.

LiteralInput.from_json({"identifier": "test", "uoms": [{"uom": "seconds", "reference": "dontcare"}]})
<pywps.inout.inputs.LiteralInput at 0x7f765b215e70>

The same issue will be applicable for eventual support in OAP: https://github.com/opengeospatial/ogcapi-processes/blob/d5257909ae9dbb8cf9958ef251e44cb3a903d691/core/examples/json/ProcessDescription.json#L27-L49