Reputation: 14781
I have a dataset in BigQuery with some views permissioned to it.
Via the API, I want to permission a new view for that dataset. Using the patch method:
...
#permission the view
dataset_ref = {'datasetId': 'dataset_b', 'projectId': 'foo'}
update = {'access': [
{
"view": {
"projectId": 'foo',
"datasetId": 'dataset_b',
"tableId": 'v_test'
}
}
]}
datasets = service.datasets()
datasets.patch(body=update, **dataset_ref).execute()
But, instead of adding the new view to the list of permissioned views, it replaces them all. I thought only the update method would do this. From the update docs:
Warning: The specified access list completely overwrites the existing access list. If you specify an empty access list, you will revoke access to everyone except yourself; you cannot remove all owners from a dataset.
From the patch docs:
Updates information in an existing dataset. The update method replaces the entire dataset resource, whereas the patch method only replaces fields that are provided in the submitted dataset resource. This method supports patch semantics.
Is it possible to just add a new view using the patch method?
(I know it's possible to provide multiple views in the patch request, but that would mean having to query the dataset first for all its existing permissions and then adding the new one - messy)
Upvotes: 2
Views: 679
Reputation: 11
I've just come across the same issue and spent some time looking for the answer on how to update the access entry as I was getting the "Cannot remove all owners from a dataset" message.
This doesn't answer your patch question, but provides a work around to the error and hopefully saves others some time.
the updating-datasets docs resolved my issue but yes, it grabs all entries appends and updates them all.
Upvotes: 1
Reputation: 172954
The update method replaces the entire dataset resource, whereas the patch method only replaces fields that are provided in the submitted dataset resource.
The key above is - the patch method only replaces fields that are provided
This means that access property will be REPLACED - the whole access property (with exception of case when you provide empty list - because at least one owner must be present at any time)
So, unfortunatelly you need to provide whole acl list by first retrieving current acl and adding new entries to it
Upvotes: 3