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

Made user info not required for RedisDSN. This will fix the issue #1275 #1302

Closed
wants to merge 9 commits into from

Conversation

kesavkolla
Copy link

@kesavkolla kesavkolla commented Mar 11, 2020

Change Summary

Making user info optional for RedisDSN. Most of the redis instances will have either no authentication or only password is needed.

Related issue number

Fix #1275

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/1275-kesavkolla.md file added describing change
    (see changes/README.md for details)

@codecov
Copy link

codecov bot commented Mar 11, 2020

Codecov Report

Merging #1302 into master will decrease coverage by 0.05%.
The diff coverage is 83.33%.

@@             Coverage Diff             @@
##            master    #1302      +/-   ##
===========================================
- Coverage   100.00%   99.94%   -0.06%     
===========================================
  Files           21       21              
  Lines         3770     3772       +2     
  Branches       749      750       +1     
===========================================
  Hits          3770     3770              
- Misses           0        1       +1     
- Partials         0        1       +1     
Impacted Files Coverage Δ
pydantic/networks.py 99.22% <83.33%> (-0.78%) ⬇️

Continue to review full report at Codecov.

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

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

should we modify user_required to be satisfied by user or password rather than just user?

changes/1275-kesavkolla.md Outdated Show resolved Hide resolved
@samuelcolvin
Copy link
Member

@kesavkolla any chance of this getting fixed?

@kesavkolla
Copy link
Author

sorry I didn't understand the comment. I thought it's waiting on you to merge

@samuelcolvin
Copy link
Member

no, I've made suggestions, and asked for some more changes.

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
@kesavkolla
Copy link
Author

should we modify user_required to be satisfied by user or password rather than just user?

I think that is a good idea of chanding the behaviour of user_required. Sometimes user is is there password is not there other times both exist. So we should really make the interpreation of user_required to any of user or password is present.

@kesavkolla
Copy link
Author

@samuelcolvin anything else to do for this PR?

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

I'm so sorry to have changed my mind on this - I know it's very annoying.

I think we need to either add password_required and credentials_required (which is either user or password provided), or remove the change in logic and just set user_required = False on RedisDsn.

Having looked again neither username or password are required for redis, so fixing the original error on this should be very simple.

@@ -189,7 +190,8 @@ def validate(cls, value: Any, field: 'ModelField', config: 'BaseConfig') -> 'Any
raise errors.UrlSchemePermittedError(cls.allowed_schemes)

user = parts['user']
if cls.user_required and user is None:
password = parts['password']
if cls.user_required and user is None and password is None:
Copy link
Member

Choose a reason for hiding this comment

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

Humm, this is a breaking change (and arguably a bug) since now user is no longer required when user_required = True - just password will suffice .

To fix this, either we need to:

  1. add password_required (and then probably user_or_password_required, maybe credentials_required would be a better name)
  2. or, leave this logic unchanged and just change user_required = False on RedisDsn

I think I favour option 1., but on RedisDsn it looks like neither user or password are required, so it doesn't make much difference in this case.

@@ -53,7 +53,7 @@ def url_regex() -> Pattern[str]:
if _url_regex_cache is None:
_url_regex_cache = re.compile(
r'(?:(?P<scheme>[a-z][a-z0-9+\-.]+)://)?' # scheme https://tools.ietf.org/html/rfc3986#appendix-A
r'(?:(?P<user>[^\s:/]+)(?::(?P<password>[^\s/]*))?@)?' # user info
r'(?:(?P<user>[^\s:/]+)?(?::(?P<password>[^\s/]*))?@)?' # user info
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
r'(?:(?P<user>[^\s:/]+)?(?::(?P<password>[^\s/]*))?@)?' # user info
r'(?:(?P<user>[^\s:/]+)?' # user
r'(?::(?P<password>[^\s/]*))?@)?' # password

as i understand it user and password are now independent, so should go on separate lines.

@@ -0,0 +1 @@
Made user info optional for `RedisDSN`
Copy link
Member

Choose a reason for hiding this comment

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

If we're adding password_required and credentials_required we should put that in the change description.

@samuelcolvin
Copy link
Member

Thanks so much for working on this.

In the end to get something out, I've implemented a simple fix in #1658.

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.

RedisDSN with out username
2 participants