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

__post_init__ and validators are not triggered in class inherited from stdlib dataclass in 1.10.1 #4477

Closed
7 of 16 tasks
togrishka opened this issue Sep 4, 2022 · 1 comment · Fixed by #4484
Closed
7 of 16 tasks
Labels
bug V1 Bug related to Pydantic V1.X unconfirmed Bug not yet confirmed as valid/applicable

Comments

@togrishka
Copy link

togrishka commented Sep 4, 2022

Initial Checks

  • I have searched GitHub for a duplicate issue and I'm sure this is something new
  • I have searched Google & StackOverflow for a solution and couldn't find anything
  • I have read and followed the docs and still think this is a bug
  • I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like FastAPI or mypy)

Description

post_init and validator are not triggered in the following code. However, uncommenting any of the lines: py_dataclass(D_C_Base) or b: str = "string" solves the issue.
Versions 1.9.x could trigger both post_init and validators without these lines.

Example Code

from dataclasses import dataclass
from pydantic.dataclasses import dataclass as py_dataclass
from pydantic import validator


@dataclass
class D_C_Base:
    a: float = 1.0

# py_dataclass(D_C_Base)

@py_dataclass
class D_C_Child(D_C_Base):
    # b: str = "string"
    
    def __post_init__(self):
        print('POST_INIT')
        
    @validator('a')
    def validate_a(cls, value):
        print(f'Validating "a" is {value}')

d_c_class = D_C_Child()

Python, Pydantic & OS Version

pydantic version: 1.10.1
pydantic compiled: True
install path: C:\Users\TestUser\.conda\envs\py38\Lib\site-packages\pydantic
               python version: 3.8.13 (default, Mar 28 2022, 06:59:08) [MSC v.1916 64 bit (AMD64)]
platform: Windows-10-10.0.22000-SP0
optional deps. installed: ['typing-extensions']

Also,

pydantic version: 1.10.1
pydantic compiled: True
install path: /local/envs/py39_test/lib/python3.9/site-packages/pydantic
               python version: 3.9.1 (default, Dec 11 2020, 14:32:07)  [GCC 7.3.0]
platform: Linux-3.10.0-1160.66.1.el7.x86_64-x86_64-with-glibc2.17
optional deps. installed: ['typing-extensions']

Affected Components

@togrishka togrishka added bug V1 Bug related to Pydantic V1.X unconfirmed Bug not yet confirmed as valid/applicable labels Sep 4, 2022
@togrishka togrishka changed the title __post_init__ and validators are not triggered in class inherited from stdlib dataclass __post_init__ and validators are not triggered in class inherited from stdlib dataclass in 1.10.1 Sep 4, 2022
@samuelcolvin
Copy link
Member

I can confirm the behaviour, @PrettyWood can you look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X unconfirmed Bug not yet confirmed as valid/applicable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants