Skip to content

Commit

Permalink
Fix serialization issue for JSON dumps in "show states" mode
Browse files Browse the repository at this point in the history
This implements a generic fix to use `repr()` for data to be encoded to JSON values that would normally cause errors like:
`TypeError: Object of type datetime is not JSON serializable`

Signed-off-by: Tobias Wolf <[email protected]>
  • Loading branch information
NotTheEvilOne committed Sep 21, 2024
1 parent 94a029c commit ad6f0da
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/rookify/modules/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def ssh(self) -> SSH:
return self._ssh

def _get_readable_json_dump(self, data: Any) -> Any:
return json.dumps(data, sort_keys=True, indent="\t")
return json.dumps(data, default=repr, sort_keys=True, indent="\t")

def get_readable_key_value_state(self) -> Optional[Dict[str, str]]:
"""
Expand Down

0 comments on commit ad6f0da

Please sign in to comment.