Skip to content

Commit a7559fe

Browse files
AleksMatandymccurdy
authored andcommitted
Fix for HSET argument validation to allow any non-None key
Fixes #1337 Fixes #1341
1 parent 252c840 commit a7559fe

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* 3.5.1 (May 9, 2020)
2+
* Fix for HSET argument validation to allow any non-None key. Thanks
3+
@AleksMat, #1337, #1341
14
* 3.5.0 (April 29, 2020)
25
* Removed exception trapping from __del__ methods. redis-py objects that
36
hold various resources implement __del__ cleanup methods to release

redis/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,14 +3034,14 @@ def hlen(self, name):
30343034
def hset(self, name, key=None, value=None, mapping=None):
30353035
"""
30363036
Set ``key`` to ``value`` within hash ``name``,
3037-
Use ``mappings`` keyword args to set multiple key/value pairs
3038-
for a hash ``name``.
3037+
``mapping`` accepts a dict of key/value pairs that that will be
3038+
added to hash ``name``.
30393039
Returns the number of fields that were added.
30403040
"""
3041-
if not key and not mapping:
3041+
if key is None and not mapping:
30423042
raise DataError("'hset' with no key value pairs")
30433043
items = []
3044-
if key:
3044+
if key is not None:
30453045
items.extend((key, value))
30463046
if mapping:
30473047
for pair in mapping.items():

tests/test_commands.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,10 @@ def test_hget_and_hset(self, r):
16121612
# key inside of hash that doesn't exist returns null value
16131613
assert r.hget('a', 'b') is None
16141614

1615+
# keys with bool(key) == False
1616+
assert r.hset('a', 0, 10) == 1
1617+
assert r.hset('a', '', 10) == 1
1618+
16151619
def test_hset_with_multi_key_values(self, r):
16161620
r.hset('a', mapping={'1': 1, '2': 2, '3': 3})
16171621
assert r.hget('a', '1') == b'1'

0 commit comments

Comments
 (0)