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

Regression in v1.9.0: dataclass as a field type on itself #3675

Closed
3 tasks done
veikman opened this issue Jan 14, 2022 · 3 comments · Fixed by #3713
Closed
3 tasks done

Regression in v1.9.0: dataclass as a field type on itself #3675

veikman opened this issue Jan 14, 2022 · 3 comments · Fixed by #3713
Labels
bug V1 Bug related to Pydantic V1.X
Milestone

Comments

@veikman
Copy link

veikman commented Jan 14, 2022

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I 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.

@veikman veikman added the bug V1 Bug related to Pydantic V1.X label Jan 14, 2022
@samuelcolvin
Copy link
Member

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
Copy link
Member

PrettyWood commented 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
Copy link
Contributor

uriyyo commented Jan 21, 2022

@PrettyWood I will take a closer look today, hope will figure out how to fix this one.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants