Skip to content

Field title and description being overridden for Enums. #1748

Closed
@joshourisman

Description

Bug

When using the Field() function with an Enum, I can set an alias, but if I try to set a title or description they are ignored for default values of both (the name of the Enum subclass for the title, and 'An enumeration' for the description).

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

             pydantic version: 1.6.1
            pydantic compiled: True
                 install path: /Users/joshourisman/.local/share/virtualenvs/forms-test-3oF3wXzB/lib/python3.8/site-packages/pydantic
               python version: 3.8.3 (default, Jun 30 2020, 11:16:06)  [Clang 11.0.0 (clang-1100.0.33.8)]
                     platform: macOS-10.15.5-x86_64-i386-64bit
     optional deps. installed: []

>>> from enum import Enum                          
>>> from pydantic import BaseModel, Field          
>>> class TestEnum(str, Enum): 
...     foo = 'foo' 
...     bar = 'bar'                                
>>> class TestModel(BaseModel): 
...     test: TestEnum = Field(alias='functioning_alias', title='I Will Be Ignored')                      
>>> TestModel.schema()                             
{'title': 'TestModel', 'type': 'object', 'properties': {'functioning_alias': {'$ref': '#/definitions/TestEnum'}}, 'required': ['functioning_alias'], 'definitions': {'TestEnum': {'title': 'TestEnum', 'description': 'An enumeration.', 'enum': ['foo', 'bar'], 'type': 'string'}}}

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions