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

InvalidURI mongodb+srv:// URIs must not include a port number #7331

Closed
1 task done
tonal opened this issue Sep 5, 2023 · 3 comments
Closed
1 task done

InvalidURI mongodb+srv:// URIs must not include a port number #7331

tonal opened this issue Sep 5, 2023 · 3 comments
Assignees
Labels
bug V2 Bug related to Pydantic V2 unconfirmed Bug not yet confirmed as valid/applicable

Comments

@tonal
Copy link

tonal commented Sep 5, 2023

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

mongodb+srv:// URIs must not include a port number

Example Code

from pydantic import BaseModel, MongoDsn

class MongoConf(BaseModel):
   uri:MongoDsn
 
m = MongoConf(uri='mongodb+srv://aaa:bbb@mongo.test.ru/test?ssl=fals')
print(m.uri)
### mongodb+srv://aaa:bbb@mongo.test.ru:27017/test?ssl=fals

Python, Pydantic & OS Version

$ python -c "import pydantic.version; print(pydantic.version.version_info())"
             pydantic version: 2.3.0
        pydantic-core version: 2.6.3
          pydantic-core build: profile=release pgo=true
                 install path: /home/tonal/.pyenv/versions/3.11.5/envs/epool-props_service/lib/python3.11/site-packages/pydantic
               python version: 3.11.5 (main, Aug 25 2023, 14:39:59) [GCC 11.4.0]
                     platform: Linux-6.2.0-32-generic-x86_64-with-glibc2.35
     optional deps. installed: ['typing-extensions']

Selected Assignee: @lig

@tonal tonal added bug V2 Bug related to Pydantic V2 unconfirmed Bug not yet confirmed as valid/applicable labels Sep 5, 2023
@hudrazine
Copy link

This issue was previously (#6774) and fixed, but appears to have been reverted in v2.2 (#7116).

For this issue, it is recommended that the following be done:

from typing import Annotated

from pydantic.networks import UrlConstraints
from pydantic_core import MultiHostUrl

MongoSRVDsn = Annotated[MultiHostUrl, UrlConstraints(allowed_schemes=['mongodb+srv'])]

@samuelcolvin
Copy link
Member

yes @as per #6774 @hudrazine's solution is correct.

@slingshotvfx
Copy link

Ran into this problem today. Should this solution be mentioned in the docs for mongodsn?

https://docs.pydantic.dev/latest/api/networks/#pydantic.networks.MongoDsn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 Bug related to Pydantic V2 unconfirmed Bug not yet confirmed as valid/applicable
Projects
None yet
Development

No branches or pull requests

5 participants