From f517287a118a372d47956f5ba831927018d1ad3e Mon Sep 17 00:00:00 2001 From: jmcbailey Date: Tue, 7 Feb 2023 10:43:36 +0000 Subject: [PATCH] Fix issue with `pack_commands` returning an empty byte sequence (#2416) Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com> --- redis/asyncio/connection.py | 3 ++- redis/connection.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/redis/asyncio/connection.py b/redis/asyncio/connection.py index 862f6f096b..e77fba30da 100644 --- a/redis/asyncio/connection.py +++ b/redis/asyncio/connection.py @@ -925,7 +925,8 @@ def pack_commands(self, commands: Iterable[Iterable[EncodableT]]) -> List[bytes] or chunklen > buffer_cutoff or isinstance(chunk, memoryview) ): - output.append(SYM_EMPTY.join(pieces)) + if pieces: + output.append(SYM_EMPTY.join(pieces)) buffer_length = 0 pieces = [] diff --git a/redis/connection.py b/redis/connection.py index b2f34293a5..24614824c5 100644 --- a/redis/connection.py +++ b/redis/connection.py @@ -976,7 +976,8 @@ def pack_commands(self, commands): or chunklen > buffer_cutoff or isinstance(chunk, memoryview) ): - output.append(SYM_EMPTY.join(pieces)) + if pieces: + output.append(SYM_EMPTY.join(pieces)) buffer_length = 0 pieces = []