Originally came up in #1329. HasField with proto3 fails on simple / singular / non-message fields.
@nathanielmanistaatgoogle Mentioned that @haberman might be able to shine some light. Josh, what should we be doing here? The current approach isn't great:
# NOTE: As of proto3, HasField() only works for message fields, not for# singular (non-message) fields. First try to use HasField and# if it fails (with a ValueError) we manually consult the fields.try:
returnmessage_pb.HasField(property_name)
exceptValueError:
all_fields=set([field.nameforfieldinmessage_pb._fields])
returnproperty_nameinall_fields
Should we bother with checking "has field", e.g.
if_has_field(key_pb.partition_id, 'dataset_id'):
...
or should we instead just check Truth-iness
ifkey_pb.partition_id.dataset_id:
...
# OR MORE STRICTifkey_pb.partition_id.dataset_id!='':
...
Originally came up in #1329.
HasFieldwithproto3fails on simple / singular / non-message fields.@nathanielmanistaatgoogle Mentioned that @haberman might be able to shine some light. Josh, what should we be doing here? The current approach isn't great:
Should we bother with checking "has field", e.g.
or should we instead just check Truth-iness