question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DISCARD without MULTI

See original GitHub issue

Hey folks,

I came across a weird issue today where one of our processes started raising ResponseError: DISCARD without MULTI when calling execute() on a pipeline object. As far as I can tell, this error should be impossible to receive since redis-py is supposed to take care of any discard/unwatching when using pipeline objects. This suggests a bug in redis-py not properly cleaning up after itself, although I’ve been reading the code and I don’t see yet how this is possible. I also don’t know how to reproduce the bug.

ERROR 2016-10-29 04:34:32.807 error expiring
Traceback (most recent call last):
  File "dmserver.py", line 1477, in push_in_worker
    redis_ops.cq_expire_items(channel_key)
  File "redis_ops.py", line 129, in cq_expire_items
    pipe.execute()
  File "/usr/lib/python2.7/dist-packages/redis/client.py", line 2626, in execute
    return execute(conn, stack, raise_on_error)
  File "/usr/lib/python2.7/dist-packages/redis/client.py", line 2521, in _execute_transaction
    self.immediate_execute_command('DISCARD')
  File "/usr/lib/python2.7/dist-packages/redis/client.py", line 2461, in immediate_execute_command
    return self.parse_response(conn, command_name, **options)
  File "/usr/lib/python2.7/dist-packages/redis/client.py", line 2584, in parse_response
    self, connection, command_name, **options)
  File "/usr/lib/python2.7/dist-packages/redis/client.py", line 585, in parse_response
    response = connection.read_response()
  File "/usr/lib/python2.7/dist-packages/redis/connection.py", line 582, in read_response
    raise response
ResponseError: DISCARD without MULTI

I’m using Redis 3.0.6 and redis-py 2.10.5.

Anyone seen anything like this before and have any suggestions?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dlcroncommented, Oct 27, 2017

I’ve also had this issue recently.

Let my summarise it just if anyone is also struggling.

You clearly cannot do the following:

> redis_db.sadd('123', *[])
*** redis.exceptions.ResponseError: wrong number of arguments for 'sadd' command

But following is allowed:

> pipe = redis_db.pipeline()
> pipe.multi()
> pipe.sadd('123', *[])
> pipe.execute()
*** redis.exceptions.ResponseError: DISCARD without MULTI

Long story short, if you are using pipeline, each of the command is queued. If one of the queued command results with an error, you might get DISCARD without MULTI. In my case arguments to sadd were computed dynamically and sometimes ended up as an empty list. This was clearly an issue in my application logic.

Since we keep the commands in the stack we could handle this specific case by introspecting the stack arguments and throw an error as soon as we add something there. In my case it is possible to know this sooner, without calling execute on pipeline.

> [..]/redis/client.py(2879)execute()
  return execute(conn, stack, raise_on_error)  # <---- we have queued commands in stack

What do you guys think about this?

0reactions
andymccurdycommented, Jul 1, 2020

This was fixing in redis-py 3.5.0. Forgot to close this issue when the error was resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DISCARD without MULTI · Issue #795 · redis/redis-py - GitHub
I am using a threaded environment. The Redis object is shared, but the pipeline is not. Here's a simplified version of my code:...
Read more >
transactions - In Redis, what happens when there is a MULTI ...
I'm curious what will happen if in one script I run MULTI and start but then the script somehow fails and I never...
Read more >
DISCARD without MULTI - Google Groups
Hi everyone, I am not understanding this exception from the code below. jedis.watch(key); String value = jedis.get(key);
Read more >
DISCARD - Redis
Discard all commands issued after MULTI. ... DISCARD. Syntax. DISCARD. Available since: 2.0.0; Time complexity: O(N), when N is the number of queued ......
Read more >
Discards - unassigned discardable variables - Microsoft Learn
Discards are placeholder variables that are intentionally unused in application code. Discards are equivalent to unassigned variables; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found