[Fix] th-cli --version Surfaces Backend And SDK Versions (#999)#85
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the get_versions function in th_cli/utils.py to return a dictionary representation of the version information using model_dump(). The reviewer suggested using model_dump(mode='json') to ensure that any future complex data types are correctly serialized for JSON output, which improves the robustness of the CLI utility.
| version_api = sync_apis.version_api | ||
| versions_info = version_api.get_test_harness_backend_version_api_v1_version_get() | ||
| return versions_info | ||
| return versions_info.model_dump() |
There was a problem hiding this comment.
Consider using model_dump(mode='json') instead of model_dump(). While the current fields in TestHarnessBackendVersion are all strings, using mode='json' ensures that any future complex types (like datetimes or enums) are automatically serialized to JSON-compatible formats. This makes the function more robust for its intended use in the CLI, where the results are likely to be printed or serialized.
| return versions_info.model_dump() | |
| return versions_info.model_dump(mode='json') |
Summary
Fixes #999.
th-cli --versionnow surfaces the backend and SDK versions returned byGET /api/v1/version.Root cause
get_versions()inth_cli/utils.pywas annotated-> dictbut actually returned a PydanticTestHarnessBackendVersioninstance from the autogeneratedSyncVersionApi. The caller inmain.py::get_extended_helpiterated it with.items(), which raisedAttributeErroron the model. The bareexcept Exception:swallowed it and replaced the block with "Not able to retrieve versions from server.", so the five backend fields (version,sha,sdk_sha,sdk_docker_tag,db_revision) were dropped CLI-side even though the API response was fine.Fix
Convert the Pydantic v2 model to a
dictviamodel_dump()inget_versions(). The existing.items()loop inget_extended_helpthen renders all backend fields without further changes.