HeyThere
HeyThere

Reputation: 583

Google protobuf 3: deprecated a field, but cannot remove the dependencies?

I have a proto A that depends on proto B. Then I deprecated the field protoB:

import "protoB.proto";

message ProtoA {
  string assignmentStatus = 1;
  protoB proto_b = 2 [deprecated = true];
}

I'd think in this case I should be able to remove the import statement right? But when I did that, the compiler complains about the dependency not being imported.

What's the deal here?

Upvotes: 17

Views: 34475

Answers (2)

Joe Eifert
Joe Eifert

Reputation: 1387

You should reserve the field(s) according to the documentation. That way no one will use them in the future.

message ProtoA {
  string assignmentStatus = 1;
  // field proto_b = 2, was removed due to bla bla
  reserved 2;
}

Upvotes: 0

Marc Gravell
Marc Gravell

Reputation: 1063864

Marking something as deprecated just ... marks it as deprecated; for example, in C# the proto_b member would be declared but marked as [Obsolete]. Since it still exists, it needs to know what to describe it as. The data is still accessible in your application, for example.

If you want to remove it: remove it:

message ProtoA {
  string assignmentStatus = 1;
  // field 2 *was* protoB proto_b = 2, now removed
}

(leaving a comment is important to avoid people accidentally reusing the field number, which could cause problems with pre-existing data).

Upvotes: 6

Related Questions