Repository: pydantic/pydantic

Issue:
`Optional[Dict[str, Any]]` broken when trying to get the schema
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!


Discussion:

Resolving patch:
diff --git a/pydantic/fields.py b/pydantic/fields.py
--- a/pydantic/fields.py
+++ b/pydantic/fields.py
@@ -356,7 +356,7 @@ def include_in_schema(self) -> bool:
         """
         False if this is a simple field just allowing None as used in Unions/Optional.
         """
-        return len(self.validators) > 1 or self.validators[0][1] != is_none_validator
+        return len(self.validators) != 1 or self.validators[0][1] != is_none_validator
 
     def is_complex(self):
         """


Test patch:
diff --git a/tests/test_schema.py b/tests/test_schema.py
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -1078,3 +1078,17 @@ class Model(BaseModel):
     base_schema['properties']['a'] = expected_schema
 
     assert Model.schema() == base_schema
+
+
+def test_optional_dict():
+    class Model(BaseModel):
+        something: Optional[Dict[str, Any]]
+
+    assert Model.schema() == {
+        'title': 'Model',
+        'type': 'object',
+        'properties': {'something': {'title': 'Something', 'type': 'object'}},
+    }
+
+    assert Model().dict() == {'something': None}
+    assert Model(something={'foo': 'Bar'}).dict() == {'something': {'foo': 'Bar'}}