close
Skip to content

Fix parsing of the is_master attribute in the URL#3367

Open
JackiLin wants to merge 8 commits intoredis:masterfrom
JackiLin:url-parsing
Open

Fix parsing of the is_master attribute in the URL#3367
JackiLin wants to merge 8 commits intoredis:masterfrom
JackiLin:url-parsing

Conversation

@JackiLin
Copy link
Copy Markdown

@JackiLin JackiLin commented Sep 4, 2024

Pull Request check-list

Please make sure to review and check all of these items:

  • Do tests and lints pass with this change?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?
  • Was the change added to CHANGES file?

NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.

Description of change

Fixed the parsing of the is_master attribute in the Redis URL.
When the Redis URL is 'redis://redis-master/1?is_master=0', it is supposed to find the slave node of redis-master for read operations. However, since is_master was parsed as '0' and not correctly interpreted as False, it failed to use the slave node.
I encountered this issue when trying to implement read-write separation using SentinelConnectionPool.


Note

Low Risk
Low risk: narrow change to URL query parsing plus a targeted regression test; behavior only changes when is_master is provided in the connection URL.

Overview
Fixes URL query parsing so the is_master option is type-cast via to_bool (e.g., is_master=0 becomes False) when building connection pools from from_url, enabling Sentinel pools to correctly target replica nodes for read operations.

Adds a regression test in tests/test_connection_pool.py covering from_url behavior when specifying the master/replica selector in the query string.

Written by Cursor Bugbot for commit 9f15d0a. This will update automatically on new commits. Configure here.

@JackiLin JackiLin marked this pull request as draft September 4, 2024 06:35
@JackiLin JackiLin marked this pull request as ready for review September 6, 2024 08:04
@vladvildanov vladvildanov added the techdebt Things that can be improved or refactored label Sep 19, 2024
@vladvildanov
Copy link
Copy Markdown
Collaborator

@JackiLin Thanks for you contribution! I would ask you to provide a test case

@JackiLin
Copy link
Copy Markdown
Author

@JackiLin Thanks for you contribution! I would ask you to provide a test case

Is it OK to add test cases like this

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to inactivity.
It will be closed in 30 days if no further activity occurs.

@github-actions github-actions Bot added the stale label Sep 26, 2025
@github-actions github-actions Bot removed the stale label Sep 27, 2025
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Comment thread tests/test_connection_pool.py
Comment thread tests/test_connection_pool.py
Copy link
Copy Markdown
Collaborator

@petyaslavova petyaslavova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @JackiLin,
I tried to complete this PR, but it seems that I don't have write permissions to your branch.
The fixed test looks like this:

        def test_ismaster_querystring(self):
                pool = redis.ConnectionPool.from_url("redis://localhost/1?is_master=0")
                assert pool.connection_class == redis.Connection
                assert pool.connection_kwargs == {
                    "host": "localhost",
                    "db": 1,
                    "is_master": False,
                }
                pool = redis.ConnectionPool.from_url("redis://localhost/1?is_master=false")
                assert pool.connection_class == redis.Connection
                assert pool.connection_kwargs == {
                    "host": "localhost",
                    "db": 1,
                    "is_master": False,
                }

Can you also fix the linters?
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changes-requested techdebt Things that can be improved or refactored

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants