tread
tread

Reputation: 11098

How to unset a protocol buffer field?

How would you unset a protocol buffer variable.

Given this .proto:

message Product {
    optional float price = 5;
}

If one tries deleting the item:

del product.price

this results:

AttributeError: can't delete attribute

If one tries setting the variable to None:

product.price = None

this results:

TypeError: Cannot set mypackage.Product.price_was to None: None has type <class 'NoneType'>, but expected one of: numbers.Real

Upvotes: 2

Views: 1852

Answers (1)

Cory Kramer
Cory Kramer

Reputation: 117886

You can use ClearField like

product.ClearField('price')

Full docs

Upvotes: 2

Related Questions