Zero is invalid as setex "seconds" argument. #721
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A few dozen times a day, Perma's self-hosted instances of Webrecorder attempt to run
Session._update_redis_and_cookie
just as a given session'sttl == 0
, which causes this line to raiseredis.exceptions.ResponseError
, since0
is not a valid value forSETEX
's "seconds" argument.This PR tweaks the existing check,
if ttl < 0: ttl = duration
, to handlettl == 0
as well.Sample Stack Trace
Note: the exception appears to be raised by line 399 rather than 392 because of the "redis pipeline" context manager, which executes all collected redis commands as the context is exited. In this case, the context is being exited after 399, causing the
SETEX
command issued at 392 to actually execute, and raising the exception.Testing
I did not see an appropriate place to add a test for this behavior, but am happy to add one, if advised where you'd like it :-)