-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xreadgroup throws an exception if message was trimmed when reading pending messages #1116
Comments
Hello @xeizmendi Thanks for detecting the issue and submitting a corrective PR. |
@itamarhaber What's the intended behavior on the server side in this situation? Leaving the Message ID hanging around in the consumer group with a nil payload seems weird to me and might be an edge case that wasn't thought of. I'm fine to merge this but curious about the thinking on the server side. |
This could have other unintended side effects for users. For instance, if someone has code like this: for stream, message in r.xreadgroup(...):
for message in messages:
my_field = message['my_field']
... If all your messages contain 'my_field' it's reasonably safe to assume that the above code works fine. However with this PR now you would also need to account for an empty message. Granted, returning an empty dict is far better than raising an exception. |
The thinking afaik is that this is ok. Unacknowledged messages stay in the PEL even if deleted, and that's the meaning of a nil payload. As for the above snippet, yeah it would break but a person who's trimming/deleting a stream should probably do something like: for message in messages:
if not message:
# The message was deleted before it was acked - do something :)
continue
my_field = message['my_field']
... Ref: redis/redis#5754 (and mebbe redis/redis#5739). |
relate to redis/redis#5718 |
Any chance the PR will be merged? |
Merged. Thanks! |
Version: 3.0.1
Platform: Python 3.6.6 on Debian 9 and Redis 5.0.2
Description: If messages get deleted from a STREAM via XADD with MAXLEN or XTRIM in a stream where there is an existing consumer group after it's consumed but before being acked, when you consume the pending messages using XREADGROUP with id 0, redis returns a (nil) as the payload of the messages instead of field key/value pairs. This causes xreadgroup to throw an exception:
You can see this is the expected behaviour in Redis's source code:
https://github.com/antirez/redis/blob/5.0.2/src/t_stream.c#L1031
The text was updated successfully, but these errors were encountered: