-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
Initial Checks
- I confirm that I'm using Pydantic V2
Description
I rely on the fact that my URLs don't have any trailing slashes, so I had a validator that stripped the trailing slash in pydantic v1.
In pydantic v2, the AnyHttpUrl
type always appends a slash to the URL even if none is provided.
Example Code
from pydantic import AnyHttpUrl
assert str(AnyHttpUrl("http://example.org")) == "http://example.org" # Fails
assert str(AnyHttpUrl("http://example.org")) == "http://example.org/" # Succeed
Python, Pydantic & OS Version
pydantic version: 2.1.1
pydantic-core version: 2.4.0
pydantic-core build: profile=release pgo=true mimalloc=true
install path: /home/jo/code/github.com/libretime/libretime/shared/.venv/lib/python3.11/site-packages/pydantic
python version: 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
platform: Linux-6.1.0-10-amd64-x86_64-with-glibc2.36
optional deps. installed: ['typing-extensions']
Selected Assignee: @adriangb
pydantic-hooky, Lawouach, Kastakin, khalo-sa, botsman and 1 more