fix(text): don't crash on --query lists mixing scalars and objects - #10527
Open
devteamaegis wants to merge 1 commit into
Open
fix(text): don't crash on --query lists mixing scalars and objects#10527devteamaegis wants to merge 1 commit into
devteamaegis wants to merge 1 commit into
Conversation
_format_list treats a list as a list of dicts when *any* element is a dict, but _all_scalar_keys then called .items() on every element. A --query multi-select list such as '[InstanceId, State]' returns a scalar alongside an object, so --output text exited 255 with AttributeError: 'str' object has no attribute 'items'. Skip non-dict elements when collecting the scalar keys; _format_text already renders them on their 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 textexits 255 on a--querymulti-select list that mixes a scalar with an object.--output jsonhandles the same data fine.[InstanceId, State]is ordinary JMESPath —InstanceIdis a string andStateis an object — so any query of that shape kills the command. Nothing is printed at all.Why it happens
_format_listdecides a list is "a list of dicts" if any element is a dict:but
_all_scalar_keysthen calls.items()on every element, so one non-dict in the list raises. The sibling branch for nested lists already tolerates mixed content (_partition_list); this branch did not.The fix
Skip non-dict elements when collecting scalar keys. The loop right below already routes each element through
_format_text, which renders scalars and nested lists on their own — so the mixed list now prints:The test
test_dicts_mixed_with_scalarsandtest_dicts_mixed_with_listsintests/unit/test_text.py. Both fail ondevelopwith theAttributeErrorand pass with the fix:tests/unit/test_text.py tests/unit/output/ tests/unit/test_table.py— 59 passed.