Skip to content

api: fix --all returning no output on single-page results - #78

Merged
brandonc merged 1 commit into
hashicorp:mainfrom
jordanenglish:fix/api-all-single-page
Jul 14, 2026
Merged

api: fix --all returning no output on single-page results#78
brandonc merged 1 commit into
hashicorp:mainfrom
jordanenglish:fix/api-all-single-page

Conversation

@jordanenglish

Copy link
Copy Markdown
Contributor

Description

tfctl api --all returns no output when the result fits in a single page. In
paginateResponse, the initial response body is read in full to look for a
next pagination link. On the single-page path (no next link, or the payload
is not a paginated collection) the function returned the response without
restoring that drained body, so rendering saw an empty body. In practice this
surfaced as a not a JSON:API envelope error rather than the expected result.

This restores the buffered body before returning on that path, mirroring what
the multi-page path already does when it re-wraps the merged body.

Example Output

Before (against a resource whose result fits on one page):

$ tfctl api /organizations/my-org/workspaces --all
Error: not a JSON:API envelope

After:

$ tfctl api /organizations/my-org/workspaces --all
# renders the workspaces as usual

PR Checklist

  • Run npx changie new or install changie to prepare a new changelog entry for the next set of release notes.
    • Added .changes/unreleased/BUG FIXES-*.yaml (kind: BUG FIXES).
  • Ensure any command changes are sensitive to these global flags:
    • --json — Force machine readable output to stdout. Does not apply to stderr.
    • --markdown — Force markdown output to stdout. Does not apply to stderr.
    • --dry-run — Don't make any actual writes or other mutations. Describe what would have changed to stderr.
    • --quiet — Don't render output to stdout.
    • No new flags or output modes. The fix restores the response body so all existing output paths (--json/--markdown/--quiet) render as they would for a non---all request. --dry-run is not applicable to api GET pagination.
  • Get the logging interface from the context and add debug logging for interesting conditions and nonfatal situations.
    • No new nonfatal conditions are introduced.
  • Run make gen/screenshot if the root command output changes.
    • Not required: root command output is unchanged.
  • Add the Autocomplete field to positional arguments and flags to assist shell autocomplete.
    • N/A: no new arguments or flags.

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

    • Reverting the PR fully removes the change; no additional revert steps or data migration.
  • If applicable, I've documented the impact of any changes to security controls.

    • N/A: no security-control changes.

paginateResponse read the initial response body to check for additional
pages but did not restore it when there were none (or the payload was not
a paginated collection). The drained body then failed to render, so
`api --all` returned no output on single-page results.

Restore the buffered body before returning on that path. Adds a test
covering --all against a single-page response.
@jordanenglish
jordanenglish marked this pull request as ready for review July 13, 2026 17:56

@brandonc brandonc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and neat fix

@brandonc
brandonc merged commit 148e7c8 into hashicorp:main Jul 14, 2026
2 checks passed
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.

2 participants