Fix --output text --query emitting a stray None for the pagination resume hint#10450
Open
Abuhaithem wants to merge 1 commit into
Open
Fix --output text --query emitting a stray None for the pagination resume hint#10450Abuhaithem wants to merge 1 commit into
--output text --query emitting a stray None for the pagination resume hint#10450Abuhaithem wants to merge 1 commit into
Conversation
When `--output text` is combined with `--query` and a paginated response is truncated (e.g. via `--max-items`), the text formatter printed the `NEXTTOKEN` resume hint by routing it through `_format_response`, which applies the user's `--query` expression. Searching the hint with a data expression yields `None`, so a stray `None` line was appended to the output, corrupting text/scripted consumers. The resume-token hint is pagination metadata, not part of the queried result set. Render it directly with `text.format_text` so the `NEXTTOKEN<tab><token>` hint is preserved regardless of `--query`.
4 tasks
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.
Fixes: #10449
Description
When
--output textis combined with--queryand a paginated response istruncated (for example via
--max-items), the CLI printed a strayNoneline:TextFormatteremits theNEXTTOKENresume-token hint through_format_response, which applies the user's--queryexpression. Evaluating adata expression against the hint object
{"NextToken": {"NextToken": "<token>"}}returnsNone, and thatNonewaswritten to stdout, corrupting text/scripted output.
The resume-token hint is pagination metadata, not part of the queried result
set, so it is now rendered directly via
text.format_text(...), bypassing--query:Scope
TextFormatteronly. The JSON and Table formatters aggregate the full resultand apply
--queryonce to the whole response, so they were never affected.--queryis absent, and none for non-truncatedresponses (no resume token, so the branch is not entered).
Changes
awscli/formatter.py— render the resume-token hint withtext.format_textinstead of
_format_responseso the global--queryis not applied to it.tests/unit/output/test_text_output.py— addTestTextPaginationResumeTokenwith two end-to-end functional tests (via
BaseAWSCommandParamsTest):--query;--query, the queried data renders, theNEXTTOKENhint ispreserved, and no
Noneline appears..changes/next-release/bugfix-text-output-pagination.json— changelog entry.Testing
$ python -m pytest tests/unit/output/test_text_output.py--querytest fails ondevelop(reproduces the bug) and passeswith this change.
tests/unit/output/,tests/unit/test_text.py, andtests/functional/kinesis/test_list_streams.pycontinue to pass.Checklist
CONTRIBUTING.md).developbranch..changes/next-release/.