Skip to content

Enum Field() schema omits extra kwargs if no other overrides exist #2697

@roxchkplusony

Description

@roxchkplusony

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

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

pydantic version: 1.8.1
            pydantic compiled: True
                 install path: /Users/victor/git/data-mesh/module-specs/specs_common/.venv/lib/python3.8/site-packages/pydantic
               python version: 3.8.6 (default, Oct 10 2020, 00:41:34)  [Clang 12.0.0 (clang-1200.0.32.2)]
                     platform: macOS-10.15.7-x86_64-i386-64bit
     optional deps. installed: ['typing-extensions']
from pydantic import BaseModel, Field


class NumEnum(int, Enum):
    one = 1
    two = 2


class BugReproModel(BaseModel):
    num_enum: NumEnum = Field(extra_field='hello')


class WorkingModel(BaseModel):
    num_enum: NumEnum = Field(default=NumEnum.two, extra_field='hello')


def test_bug_repro_model():
    assert BugReproModel.schema()['properties']['num_enum'] == {
        '$ref': '#/definitions/NumEnum',
        'extra_field': 'hello', # this is missing
    }


def test_working_model():
    assert WorkingModel.schema()['properties']['num_enum'] == {
        'allOf': [{'$ref': '#/definitions/NumEnum'}],
        'default': NumEnum.two,
        'extra_field': 'hello', # this is here
    }

Metadata

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