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

Use of stdlib dataclasses with BaseModel does not work as expected #8422

Closed
1 task done
kschwab opened this issue Dec 22, 2023 · 6 comments · Fixed by #8491
Closed
1 task done

Use of stdlib dataclasses with BaseModel does not work as expected #8422

kschwab opened this issue Dec 22, 2023 · 6 comments · Fixed by #8491

Comments

@kschwab
Copy link

kschwab commented Dec 22, 2023

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

The following Pydantic example, Use of stdlib dataclasses with BaseModel, fails to work as expected.

Specifically, the ValidationError for file.filename input should be a valid string ... does not occur. Is this expected behavior?

Example Code

No response

Python, Pydantic & OS Version

$ python3 -c "import pydantic.version; print(pydantic.version.version_info())"
              pydantic version: 2.5.2
         pydantic-core version: 2.14.5
           pydantic-core build: profile=release pgo=true
                  install path: /usr/local/lib/python3.12/site-packages/pydantic
                python version: 3.12.0 (main, Oct  2 2023, 00:00:00) [GCC 13.2.1 20230918 (Red Hat 13.2.1-3)]
                      platform: Linux-6.2.9.valarch.master.1.1-x86_64-with-glibc2.38
              related packages: pydantic-settings-2.1.0 typing_extensions-4.9.0
@kschwab kschwab added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Dec 22, 2023
@kschwab kschwab changed the title stdlib base model conversion from example does not work as expected Use of stdlib dataclasses with BaseModel does not work as expected Dec 22, 2023
@Kludex
Copy link
Member

Kludex commented Dec 28, 2023

Yes. We need to add model_config = ConfigDict(revalidate_instances='always') to the Foo model to reproduce the expected behavior.

Also, we may want to improve the wording on this section.

@Kludex Kludex added documentation good first issue and removed pending Awaiting a response / confirmation bug V2 Bug related to Pydantic V2 labels Dec 28, 2023
@baohuamap
Copy link

Hi @Kludex , I can work on this issue.

@sydney-runkle
Copy link
Member

@baohuamap,

Go for it! I can review a PR.

@patelnets
Copy link
Contributor

patelnets commented Jan 4, 2024

Sorry for taking this, but I saw that baohuamap hadn't submitted a PR and it's been 5 days so I assumed it was fair game to create one.

Here is a PR for it #8491

@baohuamap
Copy link

baohuamap commented Jan 5, 2024

Hi @patelnets, I've been waiting for any members to assign me this ticket to start working on it. But if you have done it, It's fine.

@patelnets
Copy link
Contributor

Ahh sorry about that!

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.

5 participants