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

No constructor defined for ValidationError #8026

Closed
1 task done
saber-solooki opened this issue Nov 6, 2023 · 1 comment
Closed
1 task done

No constructor defined for ValidationError #8026

saber-solooki opened this issue Nov 6, 2023 · 1 comment
Assignees

Comments

@saber-solooki
Copy link

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

I'm trying to mimic some behavior on my test and when I try to create an object of ValidationError, I'll get an error:

TypeError: No constructor defined

This is not an issue in version one.
As I checked ValidationError is inherited from ValueError which is Exception. In my understanding, it makes sense to create an object of the Exception class.

Example Code

from pydantic import ValidationError
ValidationError()

TypeError: No constructor defined

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/sabersolooki/.pyenv/versions/3.10.6/envs/myproject/lib/python3.10/site-packages/pydantic
               python version: 3.10.6 (main, Nov 25 2022, 12:24:25) [Clang 13.1.6 (clang-1316.0.21.2.5)]
                     platform: macOS-12.4-x86_64-i386-64bit
             related packages: mypy-1.6.1 typing_extensions-4.8.0 email-validator-2.1.0.post1
@saber-solooki saber-solooki added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Nov 6, 2023
@sydney-runkle sydney-runkle self-assigned this Nov 8, 2023
@sydney-runkle sydney-runkle added question duplicate and removed bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Nov 8, 2023
@sydney-runkle
Copy link
Member

Hi @saber-solooki,

Thanks for your question. As answered in this issue: #6734, you'll have to use ValidationError.from_exception_data.

You can read more in the docs here: https://docs.pydantic.dev/latest/api/pydantic_core/#pydantic_core._pydantic_core.ValidationError.from_exception_data

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

No branches or pull requests

2 participants