Skip to content

Fix admin -A -ff when all results fit on one page - #121

Open
TalLevAmi wants to merge 1 commit into
masterfrom
fix/admin-filter-fields-single-page
Open

TalLevAmi wants to merge 1 commit into
masterfrom
fix/admin-filter-fields-single-page

Conversation

@TalLevAmi

Copy link
Copy Markdown
Contributor

-ff/--filter_fields on cld admin works only through auto-pagination. When all results fit on the first page, handle_auto_pagination returned before it applied the filter, so cld admin resources -A -ff public_id max_results=500 printed every field. Without -A, the CLI accepted -ff and ignored it with no message.

Brief Summary of Changes

  • handle_auto_pagination (cloudinary_cli/utils/api_utils.py) calculates the fields to keep before the early return. When the response has no cursor, it filters each list in the response. With one page, the pagination field is not known, so the code cannot select one list.
  • handle_api_command logs -ff/--filter_fields has no effect without -A/--auto_paginate. when -ff is given without -A.
  • The -ff help text says that it requires -A.

What does this PR address?

  • GitHub issue (Add reference - #XX)
  • Refactoring
  • New feature
  • Bug fix
  • Adds more tests

Are tests included?

  • Yes
  • No

Reviewer, please note:

  • I did not make -ff work without -A. For a single-asset response, for example admin resource, it is not clear which list to filter.
  • whitelist_keys changes only lists of dicts, so lists of strings (for example tags) stay the same.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I ran the full test suite before pushing the changes and all the tests pass.

Local test run: I ran the full suite on Python 3.8 with Click 8.1.8. The new tests pass, and they fail without the fix. 8 tests in test_cli_agent.py and test_cli_config_oauth.py fail with stderr not separately captured on this branch and on master too. These tests need Click 8.2, which needs Python 3.10 or later. CI must confirm the full result.

🤖 Generated with Claude Code

`cld admin resources -A -ff public_id` returned every field when the
first response had no cursor. `handle_auto_pagination` returned before
it applied the filter. Without `-A`, `-ff` was ignored with no message.

- Apply the field filter to each list in a single-page response.
- Log a warning when `-ff` is given without `-A`.
- State in the `-ff` help text that it requires `-A`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TalLevAmi
TalLevAmi marked this pull request as ready for review September 26, 2026 16:15

@const-cloudinary const-cloudinary left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please see comment, this PR introduces regression

fields_to_keep = normalize_list_params(filter_fields)

if cursor_field not in res:
# A single page: the pagination field is unknown, so filter every list in the response.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not the best approach, when we have more than 1 list in response, irrelevant lists get completely emptied, like:
derived ✅ filtered, versions → [{}] ❌
or
derived ✅ filtered, info → [{}] ❌

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