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

Some model specs are not json-serializable by CLI #1280

Closed
davemfish opened this issue Apr 21, 2023 · 0 comments · Fixed by #1281
Closed

Some model specs are not json-serializable by CLI #1280

davemfish opened this issue Apr 21, 2023 · 0 comments · Fixed by #1281
Assignees
Labels
bug Something isn't working
Milestone

Comments

@davemfish
Copy link
Contributor

(C:\Users\dmf\projects\invest\env) λ invest getspec --json pollination
Traceback (most recent call last):
  File "C:\Users\dmf\projects\invest\env\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\dmf\projects\invest\env\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\dmf\projects\invest\env\Scripts\invest.exe\__main__.py", line 7, in <module>
  File "C:\Users\dmf\projects\invest\env\lib\site-packages\natcap\invest\cli.py", line 420, in main
    message = json.dumps(spec)
  File "C:\Users\dmf\projects\invest\env\lib\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "C:\Users\dmf\projects\invest\env\lib\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Users\dmf\projects\invest\env\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "C:\Users\dmf\projects\invest\env\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Unit is not JSON serializable

We actually have a test for this in test_model_specs.py and a special serializer in spec_utils.serialize_args_spec to format pint.Unit objects. So the problem is likely just that the CLI is not using our serializer, but just trying json.dumps instead.

@davemfish davemfish self-assigned this Apr 21, 2023
@davemfish davemfish added the bug Something isn't working label Apr 21, 2023
@davemfish davemfish added this to the 3.13.1 milestone Apr 21, 2023
davemfish added a commit to davemfish/invest that referenced this issue Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant