0

I couldn't remove a custom metadata key from a file in Firebase storage.

This is what I tried so far:

blob = bucket.get_blob("dir/file")
metadata = blob.metadata
metadata.pop('custom_key', None) # or del metadata['custom_key']
blob.metadata = metadata
blob.patch()

I also tried to set its value to None but it didn't help.

Osama
  • 324
  • 3
  • 11

1 Answers1

1

It seems that there are some reasons that could be affecting you to delete the custom metadata. I will address them individually, so it's easier for understanding.

First, it seems that when you read the metadata with blob.metadata, it only returns as a read-only - as clarified here. So, your updates will not work as you would like, using the way you are trying. The second reason, it seems that saving the metadata again back to blob, follows a different order than what you are trying - as shown here.

You can give it a try using the below code:

blob = bucket.get_blob("dir/file")
metadata = blob.metadata
metadata.pop{'custom_key': None} 
blob.patch()
blob.metadata = metadata

While this code is untested, I believe it might help you changing the orders and avoid the blob.metadata read-only situation.

In case this doesn't help you, I would recommend you to raise an issue for in the official Github repository for the Python library on Cloud Storage, for further clarifications from the developers.

gso_gabriel
  • 4,199
  • 1
  • 10
  • 22