It seems the properties.locations field is not in the model
https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/cosmos/azure-mgmt-cosmosdb/azure/mgmt/cosmosdb/models/database_account.py
However it is required to update the account:
https://docs.microsoft.com/en-us/rest/api/cosmos-db-resource-provider/databaseaccounts/createorupdate#request-body
The field comes across in the HTTP response from a GET just fine, it is just lost in deserialization.
This seem to make it hard for me to update a CosmosDB account (e.g. change a firewall) as the API does not appear to fully support PATCH (only for tags?) and I can't get the data I need to do acreate or update.
What am I missing here?
@shurd as you handled a similar issue :)
The CreateOrUpdate method actually takes a DatabaseAccountCreateUpdateParameters instance.
Yeah so that model requires locations which is missing from your swagger for GET (and thus the database_account model), so I can't fill out locations to successfully make an update call.
Prior to doing an update I'd need the full copy of the resource from a GET to safely update a field, so the database_account model needs to work.
Ideally I'd PATCH so I did not have to provide a locations, but the PATCH API is also not implemented correctly and only supports tags.
It looks like the Azure CLI just manually hacks the readLocations into locations since the invalid model loses the locations during deserialization.
Seems like in current situation you can't really programmatically update the account without some trickery that may or may not be safe.
I believe that fixing the swagger and generating the models again so that the full HTTP response from GET / LIST is available in the model would allow users access to the data they need to make updates.
This appears to be the incorrect swagger file responsible for bad models when retrieving current state
https://github.com/Azure/azure-rest-api-specs/blob/master/specification/cosmos-db/resource-manager/Microsoft.DocumentDB/stable/2015-04-08/cosmos-db.json#L4272
Locations comes back in the HTTP response, but isn't accessible via SDK.
This is the best I've come up with to try to update an account
(I'm using the raw dictionary here instead of the model, but the same applies either way)
I'm concerned this isn't safe? Could readLocations be different than locations?
resource = *GET THE ACCOUNT RESOURCE FROM CLIENT AS_DICT*
resource['properties']['locations'] = []
for loc in resource['properties'].get('readLocations'):
resource['properties']['locations'].append(
{'location_name': loc['locationName'],
'failover_priority': loc['failoverPriority'],
'is_zone_redundant': loc.get('isZoneRedundant', False)})
# Update resource
self.client.database_accounts.create_or_update(
resource['resourceGroup'],
resource['name'],
create_update_parameters=resource
)
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @shurd
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @shurd
Hi @stefangordon thank you for raising this issue. Every region on an account is a readable location, so you can use these from the GET response to form an update request. The code snippet you provided looks to be correct.
Right now, our PATCH request only supports updating tags as this behavior is required by ARM. We are currently working on supporting PATCH for all properties on the account.
And if Locations actually is returned, then the swagger should probably be updated to reflect this fact.
We will include locations in the next swagger update, which is expected in the next two weeks. We are tracking this internally as work item 509483.
Thanks for working with Microsoft on GitHub! Tell us how you feel about your experience using the reactions on this comment.
Most helpful comment
We will include locations in the next swagger update, which is expected in the next two weeks. We are tracking this internally as work item 509483.