Skip to content

Commit

Permalink
Revert "Fix default port for mongosrv DSNs (#6827)"
Browse files Browse the repository at this point in the history
This reverts commit 05341d3.
  • Loading branch information
Kludex committed Aug 14, 2023
1 parent b903d72 commit a146daa
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
7 changes: 2 additions & 5 deletions pydantic/networks.py
Expand Up @@ -4,7 +4,7 @@
import dataclasses as _dataclasses
import re
from ipaddress import IPv4Address, IPv4Interface, IPv4Network, IPv6Address, IPv6Interface, IPv6Network
from typing import TYPE_CHECKING, Any, Union
from typing import TYPE_CHECKING, Any

from pydantic_core import MultiHostUrl, PydanticCustomError, Url, core_schema
from typing_extensions import Annotated, TypeAlias
Expand Down Expand Up @@ -124,10 +124,7 @@ def __hash__(self) -> int:
UrlConstraints(allowed_schemes=['redis', 'rediss'], default_host='localhost', default_port=6379, default_path='/0'),
]
"""A type that will accept any Redis DSN."""
MongoDsn = Union[
Annotated[MultiHostUrl, UrlConstraints(allowed_schemes=['mongodb'], default_port=27017)],
Annotated[MultiHostUrl, UrlConstraints(allowed_schemes=['mongodb+srv'])],
]
MongoDsn = Annotated[MultiHostUrl, UrlConstraints(allowed_schemes=['mongodb', 'mongodb+srv'], default_port=27017)]
"""A type that will accept any MongoDB DSN."""
KafkaDsn = Annotated[Url, UrlConstraints(allowed_schemes=['kafka'], default_host='localhost', default_port=9092)]
"""A type that will accept any Kafka DSN."""
Expand Down
10 changes: 0 additions & 10 deletions tests/test_networks.py
Expand Up @@ -615,16 +615,6 @@ class Model(BaseModel):
assert m.a.hosts() == [{'username': None, 'password': None, 'host': 'localhost', 'port': 27017}]


def test_mongodsn_default_ports():
class Model(BaseModel):
a: MongoDsn

m1 = Model(a='mongodb://user:pass@localhost/app')
m2 = Model(a='mongodb+srv://user:pass@localhost/app')
assert str(m1.a) == 'mongodb://user:pass@localhost:27017/app'
assert str(m2.a) == 'mongodb+srv://user:pass@localhost/app'


def test_kafka_dsns():
class Model(BaseModel):
a: KafkaDsn
Expand Down

0 comments on commit a146daa

Please sign in to comment.