azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

The models for RoleDefinition and RoleAssignment in azure.mgmt.authorization don't return some expected properties

Open jsenich opened this issue 8 years ago • 7 comments

The RoleDefinition model is not deserializing/returning the following properties that are returned from the REST result: properties.createdOn, properties.updatedOn, properties.createdBy, properties.updatedBy

The RoleAssignment model is not deserializing/returning the properties.principalType property.

jsenich avatar Nov 15 '18 21:11 jsenich

Hi @jsenich Could you confirm the version of the package you are using, and if possible give some code? Thank you

lmazuel avatar Nov 19 '18 20:11 lmazuel

Sure, the version I'm using is azure-mgmt-authorization==0.51.0.

The code below is basically how I'm using the sdk it to get a list of RoleAssignments.

from msrestazure.azure_active_directory import ServicePrincipalCredentials
from azure.mgmt.authorization import AuthorizationManagementClient

credentials = ServicePrincipalCredentials(client_id, secret=secret, tenant=tenant)
client = AuthorizationManagementClient(credentials, subscription_id)

for assignment in client.role_assignments.list(filter='atScope()'):
    print '{0} - {1} - {2}'.format(assignment.name, assignment.principal_id, assignment.role_definition_id)

What I was expecting was for the role assignment object to contain an attribute with a value for the principalType property that is returned in the raw response but the RoleAssignment model doesn't have an attribute for this so it doesn't get deserialized. I was able to work around the issue by updating the _attribute_map for the RoleAssignment model executing my code:

client.role_assignments.models.RoleAssignment._attribute_map.update({'principal_type': {'key': 'properties.principalType', 'type': 'str'}})

jsenich avatar Nov 19 '18 21:11 jsenich

Can you print the attribute additional_properties ? This bag is used to get all attributes that were not defined in _attribute_map. Then, you should see principalType and maybe more (I'm curious to see how more).

lmazuel avatar Nov 19 '18 22:11 lmazuel

I declared an issue in our meta-description repo, used to do this SDK

lmazuel avatar Nov 19 '18 22:11 lmazuel

Thanks Laurent! So if I'm understanding you correctly the expected behavior should be that any attributes that are returned in the raw response from the API that aren't specifically defined in _attribute_map for the various models should appear in the additional_properties attribute?

I have run into the same issue with other management sdks as well where I'm expecting attributes that are returned by the api but don't appear in the attributes of the model or model additional_properties. What's the proper mechanism for reporting those issues too?

jsenich avatar Nov 20 '18 13:11 jsenich

Hi @jsenich Sorry for the late answer (thanksgiving would be my best excuse :)). Yes, if you see something in additional_properties this should be considered as a bug and fix at the Swagger (meta-description of the endpoint) level.

I would suggest to open a bug here like you did, and then I open a bug in the meta-description repo. Ideally, you are able get the JSON you received with logging in DEBUG and HTTP tracing activated (client.config.enable_http_logger = True). Since the bug opened on the other repo must NOT mention anything Python specific, but only the endpoint itself.

By the way, the bug here has been fixed: https://github.com/Azure/azure-rest-api-specs/pull/4525 Python side: https://github.com/Azure/azure-sdk-for-python/pull/3845

I try to release that today.

lmazuel avatar Nov 27 '18 16:11 lmazuel

Closing, release in process as 0.51.1

lmazuel avatar Nov 27 '18 19:11 lmazuel