Skip to content

Refactor(policy): convert list method to Iterator pattern#92

Open
TanyaSingh369-svg wants to merge 3 commits intohashicorp:next-0.1.3from
TanyaSingh369-svg:refactoring/iterator-pattern/policy
Open

Refactor(policy): convert list method to Iterator pattern#92
TanyaSingh369-svg wants to merge 3 commits intohashicorp:next-0.1.3from
TanyaSingh369-svg:refactoring/iterator-pattern/policy

Conversation

@TanyaSingh369-svg
Copy link

@TanyaSingh369-svg TanyaSingh369-svg commented Feb 23, 2026

Description

Refactored the Policy resource listing from the previous ModelList pattern to the Iterator pattern.

This change aligns Policy behavior with other iterator-based resources in the SDK and enables lazy pagination via the shared '_Service._list' helper.

Changes include

  • Converted 'Policies.list()' to return Iterator[Policy] instead of returning a 'PolicyList' wrapper
  • Updated example ('examples/policy.py') to iterate over the returned iterator
  • Updated unit tests ('tests/units/test_policy.py') to consume iterator using 'list(...)'
  • Retained 'PolicyListOptions' for filtering and page size configuration

Output from tests

python -m pytest tests/units/test_policy.py -vv

tests/units/test_policy.py::TestPolicies::test_list_policies_validations PASSED
tests/units/test_policy.py::TestPolicies::test_list_policies_success_without_options PASSED
tests/units/test_policy.py::TestPolicies::test_create_policy_validations PASSED
tests/units/test_policy.py::TestPolicies::test_create_policy_success PASSED
tests/units/test_policy.py::TestPolicies::test_read_policy_success PASSED
tests/units/test_policy.py::TestPolicies::test_update_policy_success PASSED
tests/units/test_policy.py::TestPolicies::test_delete_policy_validations PASSED
tests/units/test_policy.py::TestPolicies::test_delete_policy_success PASSED
tests/units/test_policy.py::TestPolicies::test_upload_policy_success_with_bytes PASSED
tests/units/test_policy.py::TestPolicies::test_download_policy_success PASSED
tests/units/test_policy.py::TestPolicies::test_valid_create_options_success PASSED

=========================== 11 passed in 0.22s ===========================

Output from Example

examples/agent.py PASS
examples/agent_pool.py PASS
examples/apply.py PASS
examples/configuration_version.py PASS
examples/notification_configuration.py PASS
examples/oauth_client.py PASS
examples/oauth_token.py PASS
examples/org.py PASS
examples/organization_membership.py PASS
examples/plan.py PASS
examples/policy.py PASS
examples/policy_check.py PASS
examples/policy_evaluation.py PASS
examples/policy_set.py PASS
examples/policy_set_parameter.py PASS
examples/project.py PASS
examples/query_run.py PASS
examples/registry_module.py PASS
examples/registry_provider.py PASS
examples/registry_provider_version.py PASS
examples/reserved_tag_key.py PASS
examples/run.py PASS
examples/run_events.py PASS
examples/run_task.py PASS
examples/run_trigger.py PASS
examples/ssh_keys.py PASS
examples/state_versions.py PASS
examples/variable_sets.py PASS
examples/variables.py PASS
examples/workspace.py PASS
examples/workspace_resources.py PASS

Rollback Plan

If any regression or unexpected behavior is observed after merging this change:

  1. Revert this pull request using GitHub’s revert functionality or a standard 'git revert'.
  2. Restore the previous 'Policies.list()' implementation that returned the 'PolicyList' wrapper instead of an iterator.
  3. Revert updates made to the example ('examples/policy.py') and unit tests ('tests/units/test_policy.py') so they align with the original 'PolicyList' behavior.
  4. Since this refactor only affects the Policy listing logic and does not introduce schema or API changes, rollback is low risk and isolated.

No data migration, configuration changes, or external dependencies are impacted by this rollback.

@TanyaSingh369-svg TanyaSingh369-svg requested a review from a team as a code owner February 23, 2026 09:50
@hashicorp-cla-app
Copy link

hashicorp-cla-app bot commented Feb 23, 2026

CLA assistant check
All committers have signed the CLA.

@hashicorp-cla-app
Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

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