Skip to content

Commit

Permalink
Send zero arguments as zero-length bytes in proto 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
tailhook committed Sep 9, 2021
1 parent bf763d1 commit 97d0748
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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

0 comments on commit 97d0748

Please sign in to comment.