From 4bbc122eb72850b1d29d8aeb71ee9045720a579a Mon Sep 17 00:00:00 2001 From: dvora-h <67596500+dvora-h@users.noreply.github.com> Date: Thu, 11 Jan 2024 10:41:16 +0200 Subject: [PATCH] Fix: hset unexpectedly mutates the list passed to items (#3103) --- redis/commands/core.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/redis/commands/core.py b/redis/commands/core.py index 45eddef65f..dfc2296797 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -5017,14 +5017,16 @@ def hset( """ if key is None and not mapping and not items: raise DataError("'hset' with no key value pairs") - items = items or [] + pieces = [] + if items: + pieces.extend(items) if key is not None: - items.extend((key, value)) + pieces.extend((key, value)) if mapping: for pair in mapping.items(): - items.extend(pair) + pieces.extend(pair) - return self.execute_command("HSET", name, *items) + return self.execute_command("HSET", name, *pieces) def hsetnx(self, name: str, key: str, value: str) -> Union[Awaitable[bool], bool]: """