-
-
Notifications
You must be signed in to change notification settings - Fork 289
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
KeyError accessing stats page #632
Comments
When the `db` value is not included explicitly in the connection kwargs the default `0` db is used but this is not reflected in the connection kwargs. Closes rqgh-632
This is blocking our team from upgrading to django-rq 2.9.x - any idea when the fix will be merged / released? |
@csilcock there is a workaround and I feel badly for forgetting to share it. Add this function somewhere - I chose to add it to a separate module to import into settings: from urllib.parse import urlparse
def redis_with_default_db(redis_url):
"""Return a redis connection with the specified db.
Necessary to ensure that the DB is in the connection kwargs.
"""
parsed = urlparse(redis_url)
db = parsed.path.strip("/") or "0"
return parsed._replace(path=f"/{db}").geturl() Then in your REDIS_URL = redis_with_default_db(os.environ.get("REDIS_URL", "redis://")) This is not guaranteed to work universally, but the general concept could be reapplied if the connection string differs. |
When the `db` value is not included explicitly in the connection kwargs the default `0` db is used but this is not reflected in the connection kwargs. Closes gh-632
The Redis database does not need to be declared in the Redis connection string, allowing the default
0
db to be used. This is what many providers do when providing a connection string, e.g. Heroku, Render, etc. If using an existing Redis cache connection as described in the readme, noDB
will ever be included.The connection uses db
0
but the connection kwargs do not reflect this, and theget_scheduler_statistics()
function depends on the connection kwargs.django-rq/django_rq/utils.py
Lines 97 to 105 in 7c7fb63
When the
db
is not included in the connection kwargs (line 105 above), aKeyError
is raised.The text was updated successfully, but these errors were encountered: