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

fix(schema): fix schema generation for Deque field #2811

Merged
merged 2 commits into from
Sep 4, 2021

Conversation

sergejkozin
Copy link
Contributor

@sergejkozin sergejkozin commented May 18, 2021

Change Summary

The AssertionError exception occurred on schema generation when a Deque field in the Pydantic model.

from typing import Deque
from pydantic import BaseModel

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

Model.schema()

"""
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
"""

It happened because the SHAPE_DEQUE was missed in the set of array-like shapes.
(https://github.com/samuelcolvin/pydantic/blob/master/pydantic/schema.py#L439)

I updated this set and added the test_deque() case to the test_shema.py.

Related issue number

Fixes #2810

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@sergejkozin sergejkozin marked this pull request as ready for review May 18, 2021 19:36
@sergejkozin
Copy link
Contributor Author

please review

Copy link
Member

@PrettyWood PrettyWood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🙏

@PrettyWood PrettyWood merged commit 2579086 into pydantic:master Sep 4, 2021
jpribyl pushed a commit to liquet-ai/pydantic that referenced this pull request Oct 7, 2021
* fix(schema): fix schema generation for `Deque` field

* add change description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot generate a JSON schema for a models with Deque field
4 participants