Skip to content

Commit

Permalink
Fix issues with AnyHttpUrl (Related: pydantic/pydantic#6395)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavberi committed Nov 23, 2024
1 parent f80a26f commit 1a59484
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
32 changes: 21 additions & 11 deletions models.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
from datetime import datetime
from enum import Enum
from typing import Any, List
from typing import Annotated, Any, List

import strawberry
from bson import ObjectId
from pydantic import (
AnyHttpUrl,
BaseModel,
BeforeValidator,
ConfigDict,
EmailStr,
Field,
HttpUrl,
TypeAdapter,
field_validator,
)
from pydantic_core import core_schema
from pytz import timezone

http_url_adapter = TypeAdapter(HttpUrl)
HttpUrlString = Annotated[
str,
BeforeValidator(
lambda value: str(http_url_adapter.validate_python(value))
),
]


def create_utc_time():
return datetime.now(timezone("UTC"))
Expand Down Expand Up @@ -75,15 +85,15 @@ class EnumCategories(str, Enum):


class Social(BaseModel):
website: AnyHttpUrl | None = None
instagram: AnyHttpUrl | None = None
facebook: AnyHttpUrl | None = None
youtube: AnyHttpUrl | None = None
twitter: AnyHttpUrl | None = None
linkedin: AnyHttpUrl | None = None
discord: AnyHttpUrl | None = None
whatsapp: AnyHttpUrl | None = None
other_links: List[AnyHttpUrl] = Field([]) # Type and URL
website: HttpUrlString | None = None
instagram: HttpUrlString | None = None
facebook: HttpUrlString | None = None
youtube: HttpUrlString | None = None
twitter: HttpUrlString | None = None
linkedin: HttpUrlString | None = None
discord: HttpUrlString | None = None
whatsapp: HttpUrlString | None = None
other_links: List[HttpUrlString] = Field([]) # Type and URL

@field_validator("other_links")
@classmethod
Expand Down
18 changes: 9 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
anyio==4.6.2
anyio==4.6.2.post1
click==8.1.7
dnspython==2.7.0
email_validator >=2.2.0
fastapi==0.115.4
fastapi==0.115.5
graphql-core==3.2.5
greenlet==3.1.1
h11==0.14.0
idna==3.10
libcst==1.5.0
libcst==1.5.1
msgpack==1.1.0
mypy-extensions==1.0.0
pathspec==0.12.1
platformdirs==4.3.6
pydantic>=2.9.2,<3.0.0
pydantic>=2.10.1,<3.0.0
Pygments==2.18.0
pymongo==4.10.1
python-dateutil>=2.9.0.post0
Expand All @@ -22,9 +22,9 @@ requests>=2.32.3
rich==13.9.4
six==1.16.0
sniffio==1.3.1
starlette>=0.41.2,<0.42.0
strawberry-graphql[fastapi]==0.247.1
tomli==2.0.2
typer==0.12.5
starlette>=0.41.3,<0.42.0
strawberry-graphql[fastapi]==0.252.0
tomli==2.1.0
typer==0.13.1
typing-extensions>=4.12.2
uvicorn==0.32.0
uvicorn==0.32.1

0 comments on commit 1a59484

Please sign in to comment.