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

RedisDsn.build() method can not generate current redis_dsn #2296

Closed
3 tasks done
ZXiangQAQ opened this issue Jan 28, 2021 · 3 comments
Closed
3 tasks done

RedisDsn.build() method can not generate current redis_dsn #2296

ZXiangQAQ opened this issue Jan 28, 2021 · 3 comments
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@ZXiangQAQ
Copy link

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

When I use RedisDsn.build() method to generate the redis_dsn with password, it doesn't work properly.

For example:

>>> from pydantic import RedisDsn

>>> RedisDsn.build(password='123456', port='6379', host='127.0.0.1', scheme='redis')
'redis://127.0.0.1:6379'

But current_dsn is 'redis://:123456@127.0.0.1:6379'

The password is generated only when the user parameter is not None.

class RedisDsn(AnyUrl):
    allowed_schemes = {'redis'}

class AnyUrl(str):
    @classmethod
    def build(
        cls,
        *,
        scheme: str,
        user: Optional[str] = None,
        password: Optional[str] = None,
        host: str,
        port: Optional[str] = None,
        path: Optional[str] = None,
        query: Optional[str] = None,
        fragment: Optional[str] = None,
        **kwargs: str,
    ) -> str:
        url = scheme + '://'
        if user:
            url += user
            if password:
                url += ':' + password
            url += '@'
        url += host
        if port:
            url += ':' + port
        if path:
            url += path
        if query:
            url += '?' + query
        if fragment:
            url += '#' + fragment
        return url

But redis versions prior of Redis 6 were only able to understand the one argument version of the command: AUTH <password>,

not required user parameter.

https://redis.io/commands/auth

@ZXiangQAQ ZXiangQAQ added the bug V1 Bug related to Pydantic V1.X label Jan 28, 2021
@PrettyWood
Copy link
Member

Hi @ZXiangQAQ
This has already been fixed in #1911.
This will be available in 1.8.
In the meantime you can install pydantic with the right merge commit
pip install -U git+https://github.com/samuelcolvin/pydantic.git@aacf5920402f374069af0c80e37d4d251f418d35
Hope it helps

@ZXiangQAQ
Copy link
Author

Thanks! 👍

@PrettyWood
Copy link
Member

Closing the issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
Development

No branches or pull requests

2 participants