Skip to content

Commit

Permalink
fix:formatting of error message about missing group
Browse files Browse the repository at this point in the history
  • Loading branch information
sjjessop committed Jul 12, 2023
1 parent 6220e20 commit e31250c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fakeredis/_msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
XADD_ID_LOWER_THAN_LAST = "ERR The ID specified in XADD is equal or smaller than the target stream top item"
XADD_INVALID_ID = 'ERR Invalid stream ID specified as stream command argument'
XGROUP_BUSYGROUP = 'ERR BUSYGROUP Consumer Group name already exists'
XGROUP_GROUP_NOT_FOUND_MSG = "NOGROUP No such consumer group '%s' for key name '%s'"
XGROUP_GROUP_NOT_FOUND_MSG = "NOGROUP No such consumer group '{1}' for key name '{0}'"
XGROUP_KEY_NOT_FOUND_MSG = (
"ERR The XGROUP subcommand requires the key to exist."
" Note that for CREATE you may want to use the MKSTREAM option to create an empty stream automatically.")
Expand Down
12 changes: 6 additions & 6 deletions fakeredis/commands_mixins/streams_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def xreadgroup(self, group_const, group_name, consumer_name, *args):
raise SimpleError(msgs.XGROUP_KEY_NOT_FOUND_MSG)
group: StreamGroup = item.value.group_get(group_name)
if not group:
raise SimpleError(msgs.XGROUP_GROUP_NOT_FOUND_MSG.format(left_args[i], group_name))
raise SimpleError(msgs.XGROUP_GROUP_NOT_FOUND_MSG.format(left_args[i].decode(), group_name.decode()))
group_params.append((group, left_args[i], left_args[i + num_streams],))
if timeout is None:
return self._xreadgroup(consumer_name, group_params, count, noack, False)
Expand Down Expand Up @@ -226,7 +226,7 @@ def xgroup_createconsumer(self, key, group_name, consumer_name):
raise SimpleError(msgs.XGROUP_KEY_NOT_FOUND_MSG)
group: StreamGroup = key.value.group_get(group_name)
if not group:
raise SimpleError(msgs.XGROUP_GROUP_NOT_FOUND_MSG.format(key, group_name))
raise SimpleError(msgs.XGROUP_GROUP_NOT_FOUND_MSG.format(key, group_name.decode()))
return group.add_consumer(consumer_name)

@command(name="XGROUP DELCONSUMER", fixed=(Key(XStream), bytes, bytes), repeat=(), )
Expand All @@ -235,7 +235,7 @@ def xgroup_delconsumer(self, key, group_name, consumer_name):
raise SimpleError(msgs.XGROUP_KEY_NOT_FOUND_MSG)
group: StreamGroup = key.value.group_get(group_name)
if not group:
raise SimpleError(msgs.XGROUP_GROUP_NOT_FOUND_MSG.format(key, group_name))
raise SimpleError(msgs.XGROUP_GROUP_NOT_FOUND_MSG.format(key, group_name.decode()))
return group.del_consumer(consumer_name)

@command(name="XINFO GROUPS", fixed=(Key(XStream),), repeat=(), )
Expand All @@ -257,7 +257,7 @@ def xinfo_consumers(self, key, group_name, ):
raise SimpleError(msgs.XGROUP_KEY_NOT_FOUND_MSG)
group: StreamGroup = key.value.group_get(group_name)
if not group:
raise SimpleError(msgs.XGROUP_GROUP_NOT_FOUND_MSG.format(key, group_name))
raise SimpleError(msgs.XGROUP_GROUP_NOT_FOUND_MSG.format(key, group_name.decode()))
return group.consumers_info()

@command(name="XCLAIM", fixed=(Key(XStream), bytes, bytes, Int, bytes), repeat=(bytes,), )
Expand All @@ -267,7 +267,7 @@ def xclaim(self, key, group_name, consumer_name, min_idle_ms, *args):
raise SimpleError(msgs.XGROUP_KEY_NOT_FOUND_MSG)
group: StreamGroup = stream.group_get(group_name)
if not group:
raise SimpleError(msgs.XGROUP_GROUP_NOT_FOUND_MSG.format(key, group_name))
raise SimpleError(msgs.XGROUP_GROUP_NOT_FOUND_MSG.format(key, group_name.decode()))

(idle, _time, retry, force, justid), msg_ids = extract_args(
args, ('+idle', '+time', '+retrycount', 'force', 'justid'),
Expand All @@ -291,7 +291,7 @@ def xautoclaim(self, key, group_name, consumer_name, min_idle_ms, start, *args):
raise SimpleError(msgs.XGROUP_KEY_NOT_FOUND_MSG)
group: StreamGroup = stream.group_get(group_name)
if not group:
raise SimpleError(msgs.XGROUP_GROUP_NOT_FOUND_MSG.format(key, group_name))
raise SimpleError(msgs.XGROUP_GROUP_NOT_FOUND_MSG.format(key, group_name.decode()))

keys = group.read_pel_msgs(min_idle_ms, start, count)
msgs_claimed, msgs_removed = group.claim(min_idle_ms, keys, consumer_name, None, False)
Expand Down
2 changes: 2 additions & 0 deletions test/test_mixins/test_streams_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ def test_xreadgroup(r: redis.Redis):
r.xreadgroup(group, consumer, streams={stream: ">"})
m1 = r.xadd(stream, {"foo": "bar"})
m2 = r.xadd(stream, {"bing": "baz"})
with pytest.raises(redis.exceptions.ResponseError, match="NOGROUP.*group 'group'.*key name 'stream'"):
r.xreadgroup(group, consumer, streams={stream: ">"})
r.xgroup_create(stream, group, 0)

expected = [[
Expand Down

0 comments on commit e31250c

Please sign in to comment.