-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
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
- Compatibility between releases
- Data validation/parsing
- Data serialization -
.dict()and.json() - JSON Schema
- Dataclasses
- Model Config
- Field Types - adding or changing a particular data type
- Function validation decorator
- Generic Models
- Other Model behaviour -
construct(), pickling, private attributes, ORM mode - Settings Management
- Plugins and integration with other tools - mypy, FastAPI, python-devtools, Hypothesis, VS Code, PyCharm, etc.