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

Malformed validation messages when they reference a nested key #65

Open
davemfish opened this issue Jan 17, 2025 · 0 comments · May be fixed by #72
Open

Malformed validation messages when they reference a nested key #65

davemfish opened this issue Jan 17, 2025 · 0 comments · May be fixed by #72
Labels
bug Something isn't working in progress

Comments

@davemfish
Copy link
Collaborator

davemfish commented Jan 17, 2025

A validation message that references a nested key is malformed. Here a have an incorrect type for the description:

data_model:
  bands:
  - index: 1
    gdal_type: Int16
    numpy_type: int16
    nodata: -32768.0
    description: 99
    title: ''
    units: ''

Actually the problem is that the nesting here includes a list, so the message formatting raises an exception:

Traceback (most recent call last):
  File "/home/dmf/projects/geometamaker/env/bin/geometamaker", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/dmf/projects/geometamaker/env/lib/python3.12/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dmf/projects/geometamaker/env/lib/python3.12/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/dmf/projects/geometamaker/env/lib/python3.12/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dmf/projects/geometamaker/env/lib/python3.12/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dmf/projects/geometamaker/env/lib/python3.12/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dmf/projects/geometamaker/src/geometamaker/cli.py", line 83, in validate
    echo_validation_error(error, filepath)
  File "/home/dmf/projects/geometamaker/src/geometamaker/cli.py", line 51, in echo_validation_error
    location = ', '.join(e['loc'])
               ^^^^^^^^^^^^^^^^^^^
TypeError: sequence item 2: expected str instance, int found

And naively coercing to a str leaves it looking like this,

✕ scratch/CGIAR_et0_annual_epsg_3857.tif.yml: 1 validation errors
(, ', d, a, t, a, _, m, o, d, e, l, ', ,,  , ', b, a, n, d, s, ', ,,  , 0, ,,  , ', d, e, s, c, r, i, p, t, i, o, n, ', )
    Input should be a valid string. [input_value=99, input_type=int]

Things are working okay for nested keys where all the parents are dicts, not lists. For example,

✕ scratch/CGIAR_et0_annual_epsg_3857.tif.yml: 1 validation errors
license, title
    Input should be a valid string. [input_value=0, input_type=int]
@davemfish davemfish added the bug Something isn't working label Jan 17, 2025
davemfish added a commit to davemfish/geometamaker that referenced this issue Jan 18, 2025
@davemfish davemfish linked a pull request Jan 30, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant