Skip to content

management client does not support adding custom policies #18225

@zhoxing-ms

Description

@zhoxing-ms
  • Package Name: azure-core
  • Package Version: 1.13.0
  • Operating System: All
  • Python Version: All

Describe the bug
Although a PR has added the ability to add the custom policies when no specified policies are passed in through **kwargs to the PipelineClient.
PR link: #17340

However, management client still does not support adding custom policies.
For example, the per_call_policies or per_retry_policies is passed in through **kwargs when building ResourceManagementClient. The reason for this issue is as follows:

  1. In method __init__() of ResourceManagementClient, the ARMPipelineClient is created

    self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs)

  2. When creating ARMPipelineClient, if the specified policies are not passed in through **kwargs, the default policies will be added to **kwargs before building the pipeline

    def __init__(self, base_url, **kwargs):
    if "policies" not in kwargs:
    if "config" not in kwargs:
    raise ValueError(
    "Current implementation requires to pass 'config' if you don't pass 'policies'"
    )
    kwargs["policies"] = self._default_policies(**kwargs)
    super(ARMPipelineClient, self).__init__(base_url, **kwargs)

  3. When building pipeline, only when there are no policies in **kwargs, there is logic to add custom policies. Since the default policies are passed in through **kwargs in step 2, so there is no logic to add custom policies.

    def _build_pipeline(self, config, **kwargs): # pylint: disable=no-self-use
    transport = kwargs.get('transport')
    policies = kwargs.get('policies')
    if policies is None: # [] is a valid policy list
    per_call_policies = kwargs.get('per_call_policies', [])
    per_retry_policies = kwargs.get('per_retry_policies', [])

Expected behavior
Could we consider that when building pipeline client, if the specified policies are passed in through **kwargs, these policies (in ARMPipelineClient, they are the default policies set by _default_policies) can also support appending custom policies?

ETA
Because this issue affects our migration of track 2 for resource module, and we plan to complete the merge of the migrated code by next Monday.
So this is an urgent issue and we hope to have it resolved by next Monday. Otherwise, we have to add custom policies by modifying private variables which do not conform to the code specification.

Metadata

Metadata

Assignees

Labels

Azure.CoreClientThis issue points to a problem in the data-plane of the library.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions