Repository: pydantic/pydantic

Issue:
RedisDSN with out username
# 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: []
```

<!-- Where possible please include a self-contained code snippet describing your question: -->

```py
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?



Discussion:
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`:

```py
class RedisDsn(AnyUrl):
    allowed_schemes = {'redis'}
```

E.g. without `user_required=True`
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?



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.
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...
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.

```python
redis = await aioredis.create_redis_pool(
    'redis://:sEcRet@localhost/')
```
Okay, let's remove `user_required=False` from `RedisDsn`. PR welcome.

Resolving patch:
diff --git a/pydantic/networks.py b/pydantic/networks.py
--- a/pydantic/networks.py
+++ b/pydantic/networks.py
@@ -274,7 +274,6 @@ class PostgresDsn(AnyUrl):
 
 class RedisDsn(AnyUrl):
     allowed_schemes = {'redis'}
-    user_required = True
 
 
 def stricturl(


Test patch:
diff --git a/tests/test_networks.py b/tests/test_networks.py
--- a/tests/test_networks.py
+++ b/tests/test_networks.py
@@ -324,10 +324,11 @@ class Model(BaseModel):
         Model(a='http://example.org')
     assert exc_info.value.errors()[0]['type'] == 'value_error.url.scheme'
 
-    with pytest.raises(ValidationError) as exc_info:
-        Model(a='redis://localhost:5432/app')
-    error = exc_info.value.errors()[0]
-    assert error == {'loc': ('a',), 'msg': 'userinfo required in URL but missing', 'type': 'value_error.url.userinfo'}
+    # password is not required for redis
+    m = Model(a='redis://localhost:5432/app')
+    assert m.a == 'redis://localhost:5432/app'
+    assert m.a.user is None
+    assert m.a.password is None
 
 
 def test_custom_schemes():