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

Optional[Dict[str, Any]] broken when trying to get the schema #361

Closed
dbarrosop opened this issue Jan 19, 2019 · 1 comment · Fixed by #362
Closed

Optional[Dict[str, Any]] broken when trying to get the schema #361

dbarrosop opened this issue Jan 19, 2019 · 1 comment · Fixed by #362
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@dbarrosop
Copy link

This broke since 0.17:

import json
from typing import Any, Dict, Optional

from pydantic import BaseModel


class Test(BaseModel):
    something: Optional[Dict[str, Any]]


print(json.dumps(Test.schema(), indent=4))

Traceback:

$ python test.py
Traceback (most recent call last):
  File "test.py", line 11, in <module>
    print(json.dumps(Test.schema(), indent=4))
  File "/home/dbarroso/.virtualenvs/nornir/lib/python3.6/site-packages/pydantic/main.py", line 292, in schema
    s = model_schema(cls, by_alias=by_alias)
  File "/home/dbarroso/.virtualenvs/nornir/lib/python3.6/site-packages/pydantic/schema.py", line 191, in model_schema
    model, by_alias=by_alias, model_name_map=model_name_map, ref_prefix=ref_prefix
  File "/home/dbarroso/.virtualenvs/nornir/lib/python3.6/site-packages/pydantic/schema.py", line 461, in model_process_schema
    model, by_alias=by_alias, model_name_map=model_name_map, ref_prefix=ref_prefix
  File "/home/dbarroso/.virtualenvs/nornir/lib/python3.6/site-packages/pydantic/schema.py", line 482, in model_type_schema
    f, by_alias=by_alias, model_name_map=model_name_map, ref_prefix=ref_prefix
  File "/home/dbarroso/.virtualenvs/nornir/lib/python3.6/site-packages/pydantic/schema.py", line 238, in field_schema
    ref_prefix=ref_prefix,
  File "/home/dbarroso/.virtualenvs/nornir/lib/python3.6/site-packages/pydantic/schema.py", line 440, in field_type_schema
    ref_prefix=ref_prefix,
  File "/home/dbarroso/.virtualenvs/nornir/lib/python3.6/site-packages/pydantic/schema.py", line 608, in field_singleton_schema
    ref_prefix=ref_prefix,
  File "/home/dbarroso/.virtualenvs/nornir/lib/python3.6/site-packages/pydantic/schema.py", line 515, in field_singleton_sub_fields_schema
    sub_fields = [sf for sf in sub_fields if sf.include_in_schema()]
  File "/home/dbarroso/.virtualenvs/nornir/lib/python3.6/site-packages/pydantic/schema.py", line 515, in <listcomp>
    sub_fields = [sf for sf in sub_fields if sf.include_in_schema()]
  File "/home/dbarroso/.virtualenvs/nornir/lib/python3.6/site-packages/pydantic/fields.py", line 359, in include_in_schema
    return len(self.validators) > 1 or self.validators[0][1] != is_none_validator

Is this a regression or has something changed that I need to address?

Thanks!

@samuelcolvin samuelcolvin added the bug V1 Bug related to Pydantic V1.X label Jan 20, 2019
samuelcolvin added a commit that referenced this issue Jan 20, 2019
samuelcolvin added a commit that referenced this issue Jan 20, 2019
@samuelcolvin samuelcolvin mentioned this issue Jan 20, 2019
3 tasks
@samuelcolvin
Copy link
Member

Thanks for reporting @dbarrosop, hopefully fixed on #362

samuelcolvin added a commit that referenced this issue Jan 20, 2019
samuelcolvin added a commit that referenced this issue Jan 20, 2019
alexdrydew pushed a commit to alexdrydew/pydantic that referenced this issue Dec 23, 2023
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