Skip to content

Commit

Permalink
feat: Allows field_ref to be used as a key value in FieldSet (#1756)
Browse files Browse the repository at this point in the history
Backported-from: main
Backported-to: 23.09
  • Loading branch information
Yaminyam authored and achimnol committed Dec 7, 2023
1 parent 5e2e1b6 commit bb6ace4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions changes/1756.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In order to be able to use not only alt_name but also field_ref when using the --format option of session list, add values to FieldSet.
4 changes: 3 additions & 1 deletion src/ai/backend/client/output/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def _default_formatter(self) -> AbstractOutputFormatter:

class FieldSet(UserDict, Mapping[str, FieldSpec]):
def __init__(self, fields: Sequence[FieldSpec]) -> None:
super().__init__({f.alt_name: f for f in fields})
fields_set = {f.alt_name: f for f in fields}
fields_set.update({f.field_ref: fields_set[f.alt_name] for f in fields})
super().__init__(fields_set)


T = TypeVar("T")
Expand Down
4 changes: 2 additions & 2 deletions tests/client/output/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_fieldspec_init():
]
),
)
assert f.field_ref == "key_foo { bar baz }"
assert f.field_ref == "key_foo { bar baz baz }"
assert f.field_name == "key_foo"
assert f.humanized_name == "Key Foo"
assert f.subfields["bar"].field_ref == "bar"
Expand All @@ -65,7 +65,7 @@ def test_fieldspec_init():
]
),
)
assert f.field_ref == "key_foo { bar { kaz } }"
assert f.field_ref == "key_foo { bar { kaz } bar { kaz } }"
assert f.field_name == "key_foo"
assert f.humanized_name == "Key Foo"
assert f.subfields["bar"].field_ref == "bar { kaz }"

0 comments on commit bb6ace4

Please sign in to comment.