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

Comments

Projects
None yet
2 participants
@dbarrosop
Copy link

dbarrosop commented Jan 19, 2019

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 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 referenced this issue Jan 20, 2019

Merged

tweak schema #362

3 of 3 tasks complete
@samuelcolvin

This comment has been minimized.

Copy link
Owner

samuelcolvin commented Jan 20, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment