Rahul Vedpathak
Rahul Vedpathak

Reputation: 1436

Does removing existing field from protobuf message cause issues?

I am having one protobuf message -

message Sample{
    string field1 = 1;
    string field2 = 2;
    string field3 = 3;
}

These messages are stored in datastore in binary format. So if I want to remove any of the defined field in the above message will it cause any issue in deserialization of the message from datastore?

Upvotes: 16

Views: 22072

Answers (2)

Marc Gravell
Marc Gravell

Reputation: 1062492

No. Removing fields is fine, although you might want to mark it reserved so that nobody reuses it in an incompatible way. New code with old data (with the field) will silently ignore it; old code with new data will just load without the field populated, since everything in proto3 is implicitly optional. This was more of a problem in proto2, when required was a thing. Another option is to leave the field but mark it with [deprecated = true] - it'll still exist and be populated, but some tools will mark the member with the platform-specific obsolete markers for that language/framework.

Upvotes: 25

Sushil Singh
Sushil Singh

Reputation: 31

Adding and removing fields will not cause safety issues as mentioned in the answer from Marc. The only safety you should care about it is to mark the field as reserved. This will ensure that no one uses the same field number accidentally in future

Upvotes: 3

Related Questions