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 3, 2021
1 parent bf763d1 commit efb6a05
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 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,14 @@ cdef class SansIOProtocol:
if kwargs:
raise errors.QueryArgumentError(
'expected no named arguments')
buf.write_bytes(EMPTY_RECORD_DATA)

# NullCodec requires actual empty data
if in_dc_type is EmptyTupleCodec:
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 +1125,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 +1136,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 efb6a05

Please sign in to comment.