pythongoogle-app-enginegoogle-cloud-endpointsprotorpc

Protocol RPC messages, empty/not set repeated field


I'm using Google Cloud Endpoints and protorpc messages (python), I've created endpoint to edit user information, how can I check when user sent empty value and when value wasn't sent? Client can send {languages: ''} to remove languages (set as None) or {} to do nothing. UserEditMessage.languages is checked as repeated so message always returns [] no matter if field is not set or is set as [], for non repeated field {languages: ''} returns '' and None for {}.

Example:

>>> t1 = UserEditMessage()
>>> t1
<UserEditMessage
 languages: []>
>>> t2 = UserEditMessage(languages=[])
>>> t2
<UserEditMessage
 languages: []>


>>> t1 = UserEditMessage()
>>> t1.first_name # None
>>> t2 = UserEditMessage(first_name='')
>>> t2.first_name
''

Solution

  • This is a flaw in the system right now, unfortunately. You could work around it by putting the repeated field into its own message and checking for message presence as a proxy for list presence, if you find it necessary.