protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Ruby deprecated descriptors should throw ruby warnings

Open choubacha opened this issue 9 years ago • 1 comments

To keep things backwards compatible and follow semver.org when working with our protobufs, we would like to be able to use the deprecated option: int32 old_field = 3 [deprecated=true];

This would be great if it notified the downstream consumer that the field had been deprecated. As is standard practice in ruby, this is typically done with a warning.

https://ruby-doc.org/core-2.2.0/Kernel.html#method-i-warn

This could be done simply by outputing:

warn("DEPRECATION WARNING: Field #{field_name} for message #{message_name} is deprecated, consider removing references to it")

If this is output then when one of our downstream clients upgrades to a new minor version, their code will work but will include warnings that warn about the now deprecated fields in use. If they don't reference (get or set) the field or other descriptor type, then they will get no warnings. Providing descriptor name and as much detail as possible will help the user debug their code and remove the deprecated fields.

Currently the approach is to either reserve or rename the field. This works until they update their schema, then it will start failing. This keeps the data message backwards compatible but not the generated code. Adding the deprecation warning will assist in this manner.

choubacha avatar Oct 20 '16 19:10 choubacha

I like it. We could also potentially send a warning when trying to assign a value to a deprecated field via hash on the pub side.

jcraigk avatar Oct 20 '16 19:10 jcraigk

I think could make sense to do, but we currently have no plans to implement this. We may be willing to accept a contribution for it.

haberman avatar Feb 02 '24 01:02 haberman