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

HttpUrl doesn't require TLD #9594

Closed
1 task done
Tom-Camp opened this issue Jun 6, 2024 · 2 comments · Fixed by #9620
Closed
1 task done

HttpUrl doesn't require TLD #9594

Tom-Camp opened this issue Jun 6, 2024 · 2 comments · Fixed by #9620
Assignees
Milestone

Comments

@Tom-Camp
Copy link

Tom-Camp commented Jun 6, 2024

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

Using Pydantic 2.7.1 HttpUrl accepts URLs without TLDs.

From the Pydantic code comment:
A type that will accept any http or https URL.

  • TLD required
  • Host required
  • Max length 2083

Example Code

>>>> from pydantic import BaseModel, HttpUrl, ValidationError
>>>> class MyModel(BaseModel):
...      url: HttpUrl
...
>>>> m = MyModel(url="http://www.example")
>>>> print(m.url)
http://www.example/

Python, Pydantic & OS Version

pydantic version: 2.7.1
        pydantic-core version: 2.18.2
          pydantic-core build: profile=release pgo=true
                 install path: /home/.../.cache/pypoetry/virtualenvs/.../lib/python3.11/site-packages/pydantic
               python version: 3.11.1 (main, Apr 18 2024, 14:47:59) [GCC 11.4.0]
                     platform: Linux-6.8.0-76060800daily20240311-generic-x86_64-with-glibc2.35
             related packages: typing_extensions-4.11.0
                       commit: unknown
@Tom-Camp Tom-Camp added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Jun 6, 2024
@sydney-runkle
Copy link
Member

@Tom-Camp,

Thanks for reporting this. I think this is more of a docs bug, as we defer to the URL Rust Crate for URL validity decisions. I've added this to the current milestone as a docs issue.

@sydney-runkle sydney-runkle added documentation and removed bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Jun 7, 2024
@sydney-runkle sydney-runkle self-assigned this Jun 7, 2024
@sydney-runkle sydney-runkle added this to the v2.8.0 milestone Jun 7, 2024
@sydney-runkle
Copy link
Member

Just as a side note, we'd recommend using a custom validator if you need to enforce the presence of a TLD!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants