Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send zero arguments as zero-length bytes in proto 0.12 #238

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions edgedb/protocol/codecs/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cdef uint64_t RECORD_ENCODER_INVALID = 1 << 1
cdef bytes NULL_CODEC_ID = b'\x00' * 16
cdef bytes EMPTY_TUPLE_CODEC_ID = TYPE_IDS.get('empty-tuple').bytes

EMPTY_NULL_DATA = b'\x00\x00\x00\x00'
EMPTY_RECORD_DATA = b'\x00\x00\x00\x04\x00\x00\x00\x00'


Expand Down
19 changes: 13 additions & 6 deletions edgedb/protocol/protocol.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1095,8 +1095,10 @@ cdef class SansIOProtocol:
'either positional or named arguments are supported; '
'not both')

in_dc_type = type(in_dc)

if self.protocol_version >= (0, 12):
if type(in_dc) in {NullCodec, EmptyTupleCodec}:
if in_dc_type in {NullCodec, EmptyTupleCodec}:
# TODO: drop EmptyTupleCodec when 1.0 RC1 is released.
# It's only here because 0.12 protocol is only
# partially implemented in edgedb@master right now.
Expand All @@ -1106,10 +1108,15 @@ cdef class SansIOProtocol:
if kwargs:
raise errors.QueryArgumentError(
'expected no named arguments')
buf.write_bytes(EMPTY_RECORD_DATA)

if in_dc_type is NullCodec:
buf.write_bytes(EMPTY_NULL_DATA)
else:
buf.write_bytes(EMPTY_RECORD_DATA)

return

if type(in_dc) is not ObjectCodec:
if in_dc_type is not ObjectCodec:
raise errors.QueryArgumentError(
'unexpected query argument codec')

Expand All @@ -1119,7 +1126,7 @@ cdef class SansIOProtocol:
(<ObjectCodec>in_dc).encode_args(buf, kwargs)
return
else:
if type(in_dc) is EmptyTupleCodec:
if in_dc_type is EmptyTupleCodec:
if args:
raise errors.QueryArgumentError(
'expected no positional arguments')
Expand All @@ -1130,14 +1137,14 @@ cdef class SansIOProtocol:
return

if kwargs:
if type(in_dc) is not NamedTupleCodec:
if in_dc_type is not NamedTupleCodec:
raise errors.QueryArgumentError(
'expected positional arguments, got named arguments')

(<NamedTupleCodec>in_dc).encode_kwargs(buf, kwargs)

else:
if type(in_dc) is not TupleCodec and args:
if in_dc_type is not TupleCodec and args:
raise errors.QueryArgumentError(
'expected named arguments, got positional arguments')
in_dc.encode(buf, args)
Expand Down