You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I confirm that I'm using Pydantic V2 installed directly from the main branch, or equivalent
Description
AnyHttpUrl adds a trailing slash at the end of the URL.
Since this worked in Pydantic v1 and is different from Pydantic v2's BaseModel behaviour I guess this is unwanted.
Example Code
############################################################# Using BaseSettings the assertion fails:frompydanticimportAnyHttpUrlfrompydantic_settingsimportBaseSettingsclassSettingsV2(BaseSettings):
URL: AnyHttpUrl="https://github.com"settings_v2=SettingsV2()
assertstr(settings_v2.URL) =="https://github.com"############################################################# Using BaseModel works as expected:frompydanticimportAnyHttpUrl, BaseModelclassSettingsV2_BaseModel(BaseModel):
URL: AnyHttpUrl="https://github.com"settings_base_model=SettingsV2_BaseModel()
assertstr(settings_base_model.URL) =="https://github.com"############################################################# Pydantic v1 BaseSettings worked also as expected:frompydanticimportv1aspydantic_v1classSettingsV1(pydantic_v1.BaseSettings):
URL: pydantic_v1.AnyHttpUrl="https://github.com"settings_v1=SettingsV1()
assertstr(settings_v1.URL) =="https://github.com"
No, it's extremely helpful to have the default values validated with BaseSettings - it's useful to be able to access settings_base_model.URL.host whether or not that field was set during validation.
Whereas with BaseModel it's generally preferable to reduce the overhead by not running validation on defaults, this is also how V1 behaved. The URL validation has changed/improved significantly in V2, hence the trailing slash.
noting this may be the cause of a CORS origin error I've run into when migrating to pydantic-settings, as, to my knowledge, these origins should not contain a trailing slash, and now it is being added.
Initial Checks
main
branch, or equivalentDescription
AnyHttpUrl adds a trailing slash at the end of the URL.
Since this worked in Pydantic v1 and is different from Pydantic v2's BaseModel behaviour I guess this is unwanted.
Example Code
Python, Pydantic & OS Version
Selected Assignee: @hramezani
The text was updated successfully, but these errors were encountered: