Closed
Description
Checks
- I added a descriptive title to this issueI have searched (google, github) for similar issues and couldn't find anythingI have read and followed the docs and still think this is a bug
Bug
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:
pydantic version: 1.9.0
pydantic compiled: True
install path: /home/veikman/.local/lib/python3.9/site-packages/pydantic
python version: 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
platform: Linux-5.11.0-38-generic-x86_64-with-glibc2.34
optional deps. installed: ['typing-extensions']
Minimal reproducing script:
from __future__ import annotations
from typing import List
from pydantic.dataclasses import dataclass
@dataclass
class Node:
children: List[Node]
Node.__pydantic_model__.update_forward_refs()
Node(children=[Node(children=[])]) # Case 1.
Node(children=[dict(children=[])]) # Case 2.
Case 1 in the sample script works as expected with Pydantic v1.8.2. In Pydantic 1.9.0, that upgrade being the only change to the environment, it produces this validation error:
children -> 0
value is not a valid dict (type=type_error.dict)
Case 2 works with both versions of Pydantic, indicating that the validation error message as such is correct.
I conclude that Pydantic v1.9.0 breaks support for Pydantic dataclasses as field data types on themselves (recursive nesting), for the case of input in the form of dataclass instances (case 1), which was a useful feature for unit testing. I have found no announcement in the change log that this is intentional.
Activity
samuelcolvin commentedon Jan 20, 2022
Thanks for reporting, yes I can confirm the change.
I'll to investigate soon. @PrettyWood do you have any idea why this has changed?
PrettyWood commentedon Jan 20, 2022
I just run
git bisect
, seems introduced in #2588. I'll try to dig after dinner(probably due to https://github.com/samuelcolvin/pydantic/blob/master/pydantic/typing.py#L424)
EDIT: I'll check this weekend if I can. @uriyyo do you have time to have a look on this? You'll probably be way faster and more accurate to find the right fix ;)
uriyyo commentedon Jan 21, 2022
@PrettyWood I will take a closer look today, hope will figure out how to fix this one.