Skip to content

Instantiating BlockingConnectionPool.from_url with timeout in query args fails #2983

Closed
@r0ro

Description

@r0ro

Version: 5.0.1
Platform: All
Description: Missing cast in URL_QUERY_ARGUMENT_PARSERS for "timeout" parameter causes a runtime TypeError

When instantiating a BlockingConnectionPool from url with timeout query parameter, timeout is not cast to float, resulting in timeout to be set to string in BlockingConnectionPool.init.

Later on when attempting to use the BlockingConnectionPool, comparison of timeout (as a string) to an int causes a TypeError '<' not supported between instances of 'str' and 'int'

TestCase:

>>> from redis.connection import BlockingConnectionPool
>>> pool = BlockingConnectionPool.from_url("redis://127.0.0.1:6379/1?timeout=42")
>>> pool.timeout
'42'
>>> pool.get_connection("PING")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/r0ro/.virtualenvs/backoffice/lib/python3.10/site-packages/redis/connection.py", line 1262, in get_connection
    connection = self.pool.get(block=True, timeout=self.timeout)
  File "/usr/lib/python3.10/queue.py", line 172, in get
    elif timeout < 0:
TypeError: '<' not supported between instances of 'str' and 'int'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions