Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Can't pass multiple arguments to hset(..., mappint={...}) #1261

Closed
1 task done
nxtlo opened this issue Jan 3, 2022 · 4 comments
Closed
1 task done

Can't pass multiple arguments to hset(..., mappint={...}) #1261

nxtlo opened this issue Jan 3, 2022 · 4 comments
Labels
need investigation Need to look into described issue.

Comments

@nxtlo
Copy link

nxtlo commented Jan 3, 2022

Describe the bug

Passing multiple arguments to the mapping in Redis.hset(mapping={...}) raises ResponseError.

To Reproduce

Working example.

import asyncio
import aioredis

async def main() -> None:
    redis = aioredis.Redis(decode_responses=True)
    # Only 1 key -> value
    await redis.hset("users", mapping={"me": 'user1'})
    print(await redis.hgetall("users"))
    # Returns {'me': 'user1'}
    await redis.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Example where the bug occurs

import asyncio
import aioredis

async def main() -> None:
    redis = aioredis.Redis(decode_responses=True)
    # Passing multiple key -> value to the mapping raises the error below.
    await redis.hset("users", mapping={"me": 'user1', "me2": "user2"})
    print(await redis.hgetall("users"))
    await redis.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Expected behavior

The bugged example is supposed to return a mapping with the 2 inserted keys which's {"me": "user1", "me2": "user2"}
but raises ResponseError instead.

Logs/tracebacks

Traceback (most recent call last):
  File "auth_test\t.py", line 12, in <module>
    loop.run_until_complete(main())
  File "Python310\lib\asyncio\base_events.py", line 641, in run_until_complete
    return future.result()
  File "auth_test\t.py", line 7, in main
    await redis.hset("users", mapping={"me": 'user1', "me2": "user2"})
  File "auth_test\.venv\lib\site-packages\aioredis\client.py", line 1085, in execute_command
    return await self.parse_response(conn, command_name, **options)
  File "auth_test\.venv\lib\site-packages\aioredis\client.py", line 1101, in parse_response
    response = await connection.read_response()
  File "auth_test\.venv\lib\site-packages\aioredis\connection.py", line 919, in read_response
    raise response from None
aioredis.exceptions.ResponseError: wrong number of arguments for 'hset' command

Python Version

$ python --version
Python 3.10.1

aioredis Version

$ python -m pip show aioredis
Name: aioredis
Version: 2.0.1
Summary: asyncio (PEP 3156) Redis support
Home-page: https://github.com/aio-libs/aioredis-py     
Author:
Author-email:
License: MIT
Location: \auth_test\.venv\lib\site-packages
Requires: typing-extensions, async-timeout
Required-by:

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@nxtlo nxtlo added the bug label Jan 3, 2022
@Andrew-Chen-Wang
Copy link
Collaborator

Apologies. Is this resolved in #1156?

@nxtlo
Copy link
Author

nxtlo commented Jan 8, 2022

No not really. I just installed aioredis from that branch and it still raises the same error.

  File "D:\Projects\auth_test\t.py", line 6, in main
    await r.hset("users", mapping={"me": "user1", "me2": "user2"})
  File "D:\Projects\auth_test\.venv\lib\site-packages\aioredis\client.py", line 1173, in execute_command
    return await conn.retry.call_with_retry(
  File "D:\Projects\auth_test\.venv\lib\site-packages\aioredis\retry.py", line 52, in call_with_retry
    return await do()
  File "D:\Projects\auth_test\.venv\lib\site-packages\aioredis\client.py", line 1152, in _send_command_parse_response  
    return await self.parse_response(conn, command_name, **options)
  File "D:\Projects\auth_test\.venv\lib\site-packages\aioredis\client.py", line 1188, in parse_response
    response = await connection.read_response()
  File "D:\Projects\auth_test\.venv\lib\site-packages\aioredis\connection.py", line 912, in read_response
    raise response from None
aioredis.exceptions.ResponseError: wrong number of arguments for 'hset' command

@Andrew-Chen-Wang
Copy link
Collaborator

Andrew-Chen-Wang commented Jan 8, 2022

I'm not really sure what to say since I can't reproduce this. One thing you can try is running execute_command yourself and seeing if it works with manual code. If you find a solution, please let me know:

In [8]: async def main():
   ...:     redis = aioredis.Redis(decode_responses=True)
   ...:     try:
   ...:         await redis.hset("users", mapping={"me": "user1", "me2": "user2"})
   ...:         print(1, await redis.hgetall("users"))
   ...:     except Exception as e:
   ...:         print(2, e)
   ...:     finally:
   ...:         await redis.close()
   ...: 
In [9]: await main()
1 {'me': 'user1', 'me2': 'user2'}

@Andrew-Chen-Wang Andrew-Chen-Wang added need investigation Need to look into described issue. and removed bug labels Jan 8, 2022
@nxtlo
Copy link
Author

nxtlo commented Jan 8, 2022

I figured out that the the issue was in my end, I was using Redis on windows version v=3.2.100 which's pretty a outdated build.
re-tested it on linux distro and worked fine. Will close this for now. Thanks!

@nxtlo nxtlo closed this as completed Jan 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need investigation Need to look into described issue.
Projects
None yet
Development

No branches or pull requests

2 participants