Helper for pagination conventions of streaming RPCs
The general convention for streamed responses with the pagination protocol is that the PaginationCursor
attribute must be set on the first response and only the first response. As seen in #91 (closed), an empty PaginationCursor
is not what is expected there.
This is hard to get right because of this subtle difference between the Python and Ruby gRPC libraries.
Python gRPC
A missing message field is returned back as the empty message:
>>> resp = GetTreeEntriesResponse()
>>> resp.pagination_cursor is None
False
>>> resp.pagination_cursor == PaginationCursor()
True
Despite this, fortunately, there is still a difference in Python between not setting and setting an empty value
>>> resp.HasField('pagination_cursor')
False
>>> resp2 = GetTreeEntriesResponse(pagination_cursor=PaginationCursor())
>>> resp2.HasField('pagination_cursor')
True
Also not setting and setting None
are equivalent (can be handy for code uniformity)
>>> resp3 = GetTreeEntriesResponse(pagination_cursor=None)
>>> resp3.HasField('pagination_cursor')
False
Ruby gRPC
A missing message is returned back as nil
[2] pry(main)> resp = Gitaly::GetTreeEntriesResponse.new()
=> <Gitaly::GetTreeEntriesResponse: entries: []>
[3] pry(main)> resp.pagination_cursor
=> nil