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()
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']
Initial Checks
Description
post_init and validator are not triggered in the following code. However, uncommenting any of the lines:
py_dataclass(D_C_Base)orb: str = "string"solves the issue.Versions 1.9.x could trigger both post_init and validators without these lines.
Example Code
Python, Pydantic & OS Version
Affected Components
.dict()and.json()construct(), pickling, private attributes, ORM mode