fix(table): don't crash on --query lists mixing scalars and objects - #10528
Open
devteamaegis wants to merge 1 commit into
Open
fix(table): don't crash on --query lists mixing scalars and objects#10528devteamaegis wants to merge 1 commit into
devteamaegis wants to merge 1 commit into
Conversation
_build_table decided how to treat a list by looking at current[0] only. When element 0 wasn't a dict, every element fell through to the row branch, where a dict satisfies all(self._scalar_type(el) for el in item) because that iterates the dict's keys. It was then added as a row of keys - dropping the values outright when the column counts happened to match, and raising ValueError when they didn't. A --query multi-select list such as '[InstanceId, State]' returns a scalar next to an object, so --output table exited 255. Route on whether every element is a dict, and give a dict in a mixed list a section of its own.
devteamaegis
marked this pull request as ready for review
August 3, 2026 16:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's broken
--output tableexits 255 on a--querymulti-select list that mixes a scalar with an object.--output jsonhandles the same data fine.When the column counts happen to line up it's quieter but worse — the object's keys are printed as a data row and the values are dropped:
Why it happens
_build_tabledecided how to treat a list fromcurrent[0]alone. If element 0 isn't a dict, every element falls to the row branch — and a dict passesall(self._scalar_type(el) for el in item)there, because that iterates the dict's keys. It's then added as a row of keys, which either loses the values or tripsSection.add_row's column-count check.The fix
Route on whether every element is a dict rather than just the first, and give a dict inside a mixed list a section of its own (the same thing
_build_sub_table_from_listalready does per element). Homogeneous lists of dicts and lists of lists take exactly the path they did before.The test
test_mixed_list_with_leading_scalarandtest_mixed_list_with_leading_dictintests/unit/output/test_table_formatter.py. Both fail ondevelopand pass with the fix: