Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
fix: Explicitly handle null values in some output formatters (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Nov 6, 2021
1 parent d916636 commit 1aa6fde
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes/183.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix handling of null values in some output formatters, which caused regression of `backend.ai info` command
6 changes: 6 additions & 0 deletions src/ai/backend/client/output/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def format_console(self, value: Any, field: FieldSpec) -> str:
return str(value)

def format_json(self, value: Any, field: FieldSpec) -> Any:
if value is None:
return None
if isinstance(value, decimal.Decimal):
return str(value)
elif isinstance(value, dict):
Expand All @@ -97,10 +99,14 @@ def format_json(self, value: Any, field: FieldSpec) -> Any:
class NestedDictOutputFormatter(OutputFormatter):

def format_console(self, value: Any, field: FieldSpec) -> str:
if value is None:
return "(null)"
value = json.loads(value)
return format_nested_dicts(value)

def format_json(self, value: Any, field: FieldSpec) -> Any:
if value is None:
return None
return json.loads(value)


Expand Down

0 comments on commit 1aa6fde

Please sign in to comment.