Skip to content

Commit

Permalink
Fix for HSET argument validation to allow any non-None key
Browse files Browse the repository at this point in the history
Fixes #1337
Fixes #1341
  • Loading branch information
AleksMat authored and andymccurdy committed May 9, 2020
1 parent 252c840 commit a7559fe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* 3.5.1 (May 9, 2020)
* Fix for HSET argument validation to allow any non-None key. Thanks
@AleksMat, #1337, #1341
* 3.5.0 (April 29, 2020)
* Removed exception trapping from __del__ methods. redis-py objects that
hold various resources implement __del__ cleanup methods to release
Expand Down
8 changes: 4 additions & 4 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3034,14 +3034,14 @@ def hlen(self, name):
def hset(self, name, key=None, value=None, mapping=None):
"""
Set ``key`` to ``value`` within hash ``name``,
Use ``mappings`` keyword args to set multiple key/value pairs
for a hash ``name``.
``mapping`` accepts a dict of key/value pairs that that will be
added to hash ``name``.
Returns the number of fields that were added.
"""
if not key and not mapping:
if key is None and not mapping:
raise DataError("'hset' with no key value pairs")
items = []
if key:
if key is not None:
items.extend((key, value))
if mapping:
for pair in mapping.items():
Expand Down
4 changes: 4 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,10 @@ def test_hget_and_hset(self, r):
# key inside of hash that doesn't exist returns null value
assert r.hget('a', 'b') is None

# keys with bool(key) == False
assert r.hset('a', 0, 10) == 1
assert r.hset('a', '', 10) == 1

def test_hset_with_multi_key_values(self, r):
r.hset('a', mapping={'1': 1, '2': 2, '3': 3})
assert r.hget('a', '1') == b'1'
Expand Down

0 comments on commit a7559fe

Please sign in to comment.