protocolbuffers/protobuf

Ruby deprecated descriptors should throw ruby warnings

Open

#2,275 opened on 2016年10月20日

GitHub で見る
 (2 comments) (2 reactions) (0 assignees)C++ (16,128 forks)batch import
enhancementhelp wantedruby

Repository metrics

Stars
 (71,223 stars)
PR merge metrics
 (平均マージ 2d 11h) (30d で 185 merged PRs)

説明

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.

コントリビューターガイド