Skip to content

Fix --output text --query emitting a stray None for the pagination resume hint#10450

Open
Abuhaithem wants to merge 1 commit into
aws:developfrom
Abuhaithem:fix/text-output-query-resume-token
Open

Fix --output text --query emitting a stray None for the pagination resume hint#10450
Abuhaithem wants to merge 1 commit into
aws:developfrom
Abuhaithem:fix/text-output-query-resume-token

Conversation

@Abuhaithem

@Abuhaithem Abuhaithem commented Jun 28, 2026

Copy link
Copy Markdown

Fixes: #10449

Description

When --output text is combined with --query and a paginated response is
truncated (for example via --max-items), the CLI printed a stray None line:

$ aws iam list-users --max-items 1 --output text --query 'Users[].UserName'
alice
None        # <-- bug

TextFormatter emits the NEXTTOKEN resume-token hint through
_format_response, which applies the user's --query expression. Evaluating a
data expression against the hint object
{"NextToken": {"NextToken": "<token>"}} returns None, and that None was
written 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:

$ aws iam list-users --max-items 1 --output text --query 'Users[].UserName'
alice
NEXTTOKEN	<token>   # hint preserved, no stray None

Scope

  • TextFormatter only. The JSON and Table formatters aggregate the full result
    and apply --query once to the whole response, so they were never affected.
  • No behavior change when --query is absent, and none for non-truncated
    responses (no resume token, so the branch is not entered).

Changes

  • awscli/formatter.py — render the resume-token hint with text.format_text
    instead of _format_response so the global --query is not applied to it.
  • tests/unit/output/test_text_output.py — add TestTextPaginationResumeToken
    with two end-to-end functional tests (via BaseAWSCommandParamsTest):
    • the resume hint is still emitted without --query;
    • with --query, the queried data renders, the NEXTTOKEN hint is
      preserved, and no None line appears.
  • .changes/next-release/bugfix-text-output-pagination.json — changelog entry.

Testing

$ python -m pytest tests/unit/output/test_text_output.py
  • The new --query test fails on develop (reproduces the bug) and passes
    with this change.
  • Existing tests/unit/output/, tests/unit/test_text.py, and
    tests/functional/kinesis/test_list_streams.py continue to pass.

Checklist

  • Bug fix includes tests (per CONTRIBUTING.md).
  • Targets the develop branch.
  • Code follows PEP 8 and is consistent with the surrounding module.
  • Cross-platform; no platform-specific behavior introduced.
  • Changelog entry added under .changes/next-release/.

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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: aws --output text with --query prints a spurious None line for the pagination resume-token hint

1 participant