Skip to content
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

Fix connections.py: allow to connect to Redis using a Unix socket URL… #392

Merged
merged 3 commits into from
Apr 1, 2024

Conversation

drygdryg
Copy link
Contributor

Allow to connect to Redis using a Unix socket URL without specifying the database number using querystring parameter.
Currently, when trying to connect via a Unix socket, specifying a URL without a db number, we get a parsing error. This fix allows to skip specifying the db number and set db=0 by default .
This code demonstrates buggy behavior of the URL parser:

from arq.connections import RedisSettings

settings = RedisSettings.from_dsn('unix:///run/redis/redis.sock')

Causes error:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    settings = RedisSettings.from_dsn('unix:///run/redis/redis.sock')
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.11/site-packages/arq/connections.py", line 59, in from_dsn
    database = int(conf.path.lstrip('/')) if conf.path else 0
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'run/redis/redis.sock'

While this works correcrly:

from arq.connections import RedisSettings

settings = RedisSettings.from_dsn('unix:///run/redis/redis.sock?db=0')

@codecov
Copy link

codecov bot commented Mar 18, 2023

Codecov Report

Merging #392 (f86c0c7) into main (bfa8e68) will decrease coverage by 0.29%.
The diff coverage is 0.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #392      +/-   ##
==========================================
- Coverage   98.66%   98.38%   -0.29%     
==========================================
  Files          11       11              
  Lines        1052     1054       +2     
  Branches      199      200       +1     
==========================================
- Hits         1038     1037       -1     
- Misses          6        7       +1     
- Partials        8       10       +2     
Impacted Files Coverage Δ
arq/connections.py 93.91% <0.00%> (-1.29%) ⬇️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bfa8e68...f86c0c7. Read the comment docs.

@JonasKs
Copy link
Collaborator

JonasKs commented Mar 19, 2023

Thanks for the PR 😊 Would love a test so we ensure it won't happen again.

@samuelcolvin
Copy link
Member

Looks good, I agree on tests.

@samuelcolvin samuelcolvin enabled auto-merge (squash) April 1, 2024 14:21
@samuelcolvin samuelcolvin merged commit d4a37f3 into python-arq:main Apr 1, 2024
11 checks passed
@samuelcolvin
Copy link
Member

v0.26.0b1 is released, please try it, I'll release v0.26 at the end of the week, see #441.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants