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 with out username #1275

Closed
kesavkolla opened this issue Mar 2, 2020 · 6 comments · Fixed by #1658
Closed

RedisDSN with out username #1275

kesavkolla opened this issue Mar 2, 2020 · 6 comments · Fixed by #1658
Labels
bug V1 Bug related to Pydantic V1.X help wanted Pull Request welcome

Comments

@kesavkolla
Copy link

Question

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.4
            pydantic compiled: True
                 install path: /home/kesav/.virtualenvs/smtp/lib/python3.8/site-packages/pydantic
               python version: 3.8.0 (default, Oct 28 2019, 16:14:01)  [GCC 9.2.1 20191008]
                     platform: Linux-5.3.0-40-generic-x86_64-with-glibc2.29
     optional deps. installed: []
import pydantic

class AppSettings(pydantic.BaseSettings):
   redis_dsn: pydantic.RedisDsn = 'redis://:password@integration.com'

My redis server has no user name only password it has. If I use above setting I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pydantic/env_settings.py", line 28, in pydantic.env_settings.BaseSettings.__init__
  File "pydantic/main.py", line 283, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for Test
redis_dsn
  userinfo required in URL but missing (type=value_error.url.userinfo)

How to use RedisDsn without user name?

@samuelcolvin samuelcolvin added bug V1 Bug related to Pydantic V1.X and removed question labels Mar 2, 2020
@samuelcolvin
Copy link
Member

I guess this code should be changed to require either a username or password:

https://github.com/samuelcolvin/pydantic/blob/e3243d267b06bda2d7b2213a8bad70f82171033c/pydantic/networks.py#L191-L193

PR welcome to change this.

The work around until that is fixed is to define your own RedisDsn:

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

E.g. without user_required=True

@samuelcolvin samuelcolvin added the help wanted Pull Request welcome label Mar 2, 2020
@roachsc4
Copy link

roachsc4 commented Mar 3, 2020

Why this code should be changed?
https://github.com/samuelcolvin/pydantic/blob/e3243d267b06bda2d7b2213a8bad70f82171033c/pydantic/networks.py#L191-L193
Can't we just remove user_required=True from RedisDsn?

@samuelcolvin
Copy link
Member

maybe, but it seems extremely rare that someone wants to login to a redis instance without either a username or password.

Maybe we shouldn't change the code but simply update the docs to explain you might want to use your own custom RedisDsn.

Given how easy it is to create your own, I'm concerned with catering to the 99% here. I think 99% of cases a redis server will require either a username or password.

@roachsc4
Copy link

As far as I know, there is no username in Redis - only password can be set with requirepass config parameter, so user_required=True has no sense. But may be I dont understand how RedisDSN should be used...

@kesavkolla
Copy link
Author

That is true I too didn't see any way that redis has user name. It only has password. If RedisDSN has parameter user_required=False then we can use the RedisDSN directly with aioredis.

redis = await aioredis.create_redis_pool(
    'redis://:sEcRet@localhost/')

@samuelcolvin
Copy link
Member

Okay, let's remove user_required=False from RedisDsn. PR welcome.

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 help wanted Pull Request welcome
Projects
None yet
3 participants