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

Validation error does not indicate type #7911

Open
1 task done
chbndrhnns opened this issue Oct 24, 2023 · 2 comments · May be fixed by pydantic/pydantic-core#1276
Open
1 task done

Validation error does not indicate type #7911

chbndrhnns opened this issue Oct 24, 2023 · 2 comments · May be fixed by pydantic/pydantic-core#1276
Assignees

Comments

@chbndrhnns
Copy link
Contributor

chbndrhnns commented Oct 24, 2023

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

The test below fails with an error that is confusing as it is not giving an indication of the incorrect origin type, it contains just the class name without the fully qualifying class. My input is a "URL", so I consider "URL input should be a string or URL" imprecise.

Would it be possible to distinguish between internal and external types somehow, maybe only in case of a naming conflict?

E       pydantic_core._pydantic_core.ValidationError: 1 validation error for url['http','https']
E         URL input should be a string or URL [type=url_type, input_value=URL('http://localhost:3000'), input_type=URL]
E           For further information visit https://errors.pydantic.dev/2.4/v/url_type

Example Code

import httpx
from pydantic import TypeAdapter, AnyHttpUrl


def test_():
    assert TypeAdapter(AnyHttpUrl).validate_python(httpx.URL("http://localhost:3000"))

Python, Pydantic & OS Version

pydantic version: 2.4.2
        pydantic-core version: 2.10.1
          pydantic-core build: profile=release pgo=false
                 install path: /Users/cleancoder/Library/Caches/pypoetry/virtualenvs/xxx-3il_93qV-py3.9/lib/python3.9/site-packages/pydantic
               python version: 3.9.6 (default, May  7 2023, 23:32:44)  [Clang 14.0.3 (clang-1403.0.22.14.1)]
                     platform: macOS-13.4.1-arm64-arm-64bit
             related packages: email-validator-2.0.0.post2 pydantic-extra-types-2.1.0 typing_extensions-4.8.0 pydantic-settings-2.0.3 fastapi-0.103.2
@chbndrhnns chbndrhnns added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Oct 24, 2023
@sydney-runkle sydney-runkle added feature request and removed bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Oct 24, 2023
@sydney-runkle sydney-runkle self-assigned this Oct 24, 2023
@sydney-runkle
Copy link
Member

Hi @chbndrhnns,

Thanks for reporting this. I think it's a reasonable ask, and I'd be happy to review a PR making things more clear. I think the validation error message could be a bit more specific as well.

@chbndrhnns
Copy link
Contributor Author

Skimming through the code, I noticed this requires changes to pydantic-core. My Rust knowledge might not be good enough to tackle this kind of task. This might change though. :)

@derlih derlih linked a pull request Apr 20, 2024 that will close this issue
4 tasks
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