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

Cannot generate a JSON schema for a models with Deque field #2810

Closed
3 tasks done
sergejkozin opened this issue May 18, 2021 · 1 comment · Fixed by #2811
Closed
3 tasks done

Cannot generate a JSON schema for a models with Deque field #2810

sergejkozin opened this issue May 18, 2021 · 1 comment · Fixed by #2811
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@sergejkozin
Copy link
Contributor

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.8.2
            pydantic compiled: False
                 install path: /home/sergej/Projects/pydantic/pydantic
               python version: 3.8.5 (default, Jan 27 2021, 15:41:15)  [GCC 9.3.0]
                     platform: Linux-5.4.0-72-generic-x86_64-with-glibc2.29
     optional deps. installed: ['devtools', 'dotenv', 'email-validator', 'typing-extensions']

Description

The AssertionError occurs on JSON schema generation if Deque field used in the Pydantic model.

Example

from typing import Deque

from pydantic import BaseModel


class Model(BaseModel):
    a: Deque[str]


Model.schema()

Output

Traceback (most recent call last):
  File "/home/sergej/Projects/pydantic/test_deque.py", line 10, in <module>
    Model.schema()
  File "/home/sergej/Projects/pydantic/pydantic/main.py", line 720, in schema
    s = model_schema(cls, by_alias=by_alias, ref_template=ref_template)
  File "/home/sergej/Projects/pydantic/pydantic/schema.py", line 168, in model_schema
    m_schema, m_definitions, nested_models = model_process_schema(
  File "/home/sergej/Projects/pydantic/pydantic/schema.py", line 557, in model_process_schema
    m_schema, m_definitions, nested_models = model_type_schema(
  File "/home/sergej/Projects/pydantic/pydantic/schema.py", line 598, in model_type_schema
    f_schema, f_definitions, f_nested_models = field_schema(
  File "/home/sergej/Projects/pydantic/pydantic/schema.py", line 242, in field_schema
    f_schema, f_definitions, f_nested_models = field_type_schema(
  File "/home/sergej/Projects/pydantic/pydantic/schema.py", line 503, in field_type_schema
    assert field.shape in {SHAPE_SINGLETON, SHAPE_GENERIC}, field.shape
AssertionError: 11
@sergejkozin sergejkozin added the bug V1 Bug related to Pydantic V1.X label May 18, 2021
@DarkAce65
Copy link

+1 to this. I just ran into the same error and confirmed that the linked PR fixes the bug

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.

2 participants