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

list of python dataclass broken after upgrade to 1.9.0 #3848

Closed
3 tasks done
mxlnk opened this issue Feb 22, 2022 · 2 comments · Fixed by #3819
Closed
3 tasks done

list of python dataclass broken after upgrade to 1.9.0 #3848

mxlnk opened this issue Feb 22, 2022 · 2 comments · Fixed by #3819
Labels
bug V1 Bug related to Pydantic V1.X
Milestone

Comments

@mxlnk
Copy link

mxlnk commented Feb 22, 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: my_directory/venv/lib/python3.8/site-packages/pydantic
               python version: 3.8.6 (default, Sep  6 2021, 17:04:40)  [GCC 10.3.0]
                     platform: Linux-5.13.0-28-generic-x86_64-with-glibc2.33
     optional deps. installed: ['typing-extensions']

The following snippet works as expected with version 1.8.2 but errors with version 1.9.0

from dataclasses import dataclass
from typing import List
import pydantic


@dataclass()
class A:
    a: int = 5


@dataclass()
class B_and_As:
    list_of_as: List[A]
    b: str = 'b'


def get_schema(json_cls: dataclass):
    as_pydantic = pydantic.dataclasses.dataclass(json_cls)
    schema = as_pydantic.__pydantic_model__.schema()
    print(schema)


get_schema(B_and_As)

error:

    schema = as_pydantic.__pydantic_model__.schema()
  File "pydantic/main.py", line 647, in pydantic.main.BaseModel.schema
  File "pydantic/schema.py", line 185, in pydantic.schema.model_schema
  File "pydantic/schema.py", line 617, in pydantic.schema.model_process_schema
  File "pydantic/schema.py", line 658, in pydantic.schema.model_type_schema
  File "pydantic/schema.py", line 258, in pydantic.schema.field_schema
  File "pydantic/schema.py", line 498, in pydantic.schema.field_type_schema
  File "pydantic/schema.py", line 848, in pydantic.schema.field_singleton_schema
  File "pydantic/schema.py", line 736, in pydantic.schema.field_singleton_sub_fields_schema
  File "pydantic/schema.py", line 563, in pydantic.schema.field_type_schema
  File "pydantic/schema.py", line 947, in pydantic.schema.field_singleton_schema
ValueError: Value not declarable with JSON Schema, field: name='_list_of_as' type=A required=True

on 1.8.2 it's prints as expected:

{'title': 'B_and_As', 'type': 'object', 'properties': {'list_of_as': {'title': 'List Of As', 'type': 'array', 'items': {'$ref': '#/definitions/A'}}, 'b': {'title': 'B', 'default': 'b', 'type': 'string'}}, 'required': ['list_of_as'], 'definitions': {'A': {'title': 'A', 'type': 'object', 'properties': {'a': {'title': 'A', 'default': 5, 'type': 'integer'}}}}}

Btw:

@mxlnk mxlnk added the bug V1 Bug related to Pydantic V1.X label Feb 22, 2022
@himbeles
Copy link
Contributor

Duplicate of #3658

@mxlnk
Copy link
Author

mxlnk commented Mar 16, 2022

thanks, did not see that one, sorry.

This one also fixes the problem for me #2557

@samuelcolvin samuelcolvin added this to the v1.9.1 milestone Apr 2, 2022
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.

3 participants