Pydantic: TypeError: issubclass() arg 1 must be a class for a Pattern Field

Created on 27 Jul 2020  路  2Comments  路  Source: samuelcolvin/pydantic

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.5.1
            pydantic compiled: False
                 install path: /home/yury/.cache/pypoetry/virtualenvs/chatbot-py3.6/lib/python3.6/site-packages/pydantic
               python version: 3.6.9 (default, Jul 17 2020, 12:50:27)  [GCC 8.4.0]
                     platform: Linux-5.3.0-62-generic-x86_64-with-Ubuntu-18.04-bionic
     optional deps. installed: ['typing-extensions', 'email-validator']
from pydantic import BaseModel                                                                                                                                                                      
from pydantic.schema import model_process_schema
from typing import Pattern

class Test(BaseModel): 
    f : Pattern

model_process_schema(Test, model_name_map={})                                                                                                                                                      

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-c3756917c641> in <module>
----> 1 model_process_schema(Test, model_name_map={})

~/.cache/pypoetry/virtualenvs/chatbot-py3.6/lib/python3.6/site-packages/pydantic/schema.py in model_process_schema(model, by_alias, model_name_map, ref_prefix, known_models)
    454     known_models.add(model)
    455     m_schema, m_definitions, nested_models = model_type_schema(
--> 456         model, by_alias=by_alias, model_name_map=model_name_map, ref_prefix=ref_prefix, known_models=known_models
    457     )
    458     s.update(m_schema)

~/.cache/pypoetry/virtualenvs/chatbot-py3.6/lib/python3.6/site-packages/pydantic/schema.py in model_type_schema(model, by_alias, model_name_map, ref_prefix, known_models)
    490         try:
    491             f_schema, f_definitions, f_nested_models = field_schema(
--> 492                 f, by_alias=by_alias, model_name_map=model_name_map, ref_prefix=ref_prefix, known_models=known_models
    493             )
    494         except SkipField as skip:

~/.cache/pypoetry/virtualenvs/chatbot-py3.6/lib/python3.6/site-packages/pydantic/schema.py in field_schema(field, by_alias, model_name_map, ref_prefix, known_models)
    189         schema_overrides=schema_overrides,
    190         ref_prefix=ref_prefix,
--> 191         known_models=known_models or set(),
    192     )
    193     # $ref will only be returned when there are no schema_overrides

~/.cache/pypoetry/virtualenvs/chatbot-py3.6/lib/python3.6/site-packages/pydantic/schema.py in field_type_schema(field, by_alias, model_name_map, schema_overrides, ref_prefix, known_models)
    416             schema_overrides=schema_overrides,
    417             ref_prefix=ref_prefix,
--> 418             known_models=known_models,
    419         )
    420         definitions.update(f_definitions)

~/.cache/pypoetry/virtualenvs/chatbot-py3.6/lib/python3.6/site-packages/pydantic/schema.py in field_singleton_schema(field, by_alias, model_name_map, schema_overrides, ref_prefix, known_models)
    642         f_schema['const'] = literal_value
    643 
--> 644     if issubclass(field_type, Enum):
    645         f_schema.update({'enum': [item.value for item in field_type]})
    646         # Don't return immediately, to allow adding specific types

TypeError: issubclass() arg 1 must be a class

bug

Most helpful comment

All 2 comments

Prompt fix! Great job, guys, any estimates on how long it would take to make it to pypi?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdeil picture cdeil  路  3Comments

iwoloschin picture iwoloschin  路  3Comments

vvoody picture vvoody  路  3Comments

timonbimon picture timonbimon  路  3Comments

ashears picture ashears  路  3Comments