As you already mentioned, when you want to delete all labels, it requires an update mask for the labels field.
Reviewing this documentation, please note that if a request is provided, this should not be set. Also, you will find a code example that might help you.
Additionally, you should import filed_mask_pb2 if you will update data with a FieldMask use as follows:
from google.protobuf import field_mask_pb2
Having the main question in mind, one of two methods can be used to remove a label:
Use the read-modify-write pattern to completely remove the label, which removes both the key and the value. To do this, perform these steps:
- Use the resource's get() function to read the current labels.
- Use a text editor or programmatically change the returned labels to
add or remove any necessary keys and their values.
- Call the patch() function on the resource to write the changed
labels.
To keep the key and remove the value, set the value to null, but reviewing your code, you are currently using None.
Also, consider the following documentation:Creating and managing labels and Method: projects.patch
UPDATE
Working again with your main question, here is a code that it was already tested to delete labels as you requested:
import googleapiclient.discovery
def sample_update_project_old(project_id):
manager = googleapiclient.discovery.build('cloudresourcemanager', 'v1')
request = manager.projects().get(projectId=project_id)
project = request.execute()
del project['labels']['key'] # replace 'key' with your actual key value
request = manager.projects().update(projectId=project_id, body=project)
project = request.execute()
sample_update_project_old("your-project-id")