Skip to content

Unexpected Config Error with discriminator #4773

@gluhar2006

Description

@gluhar2006

Initial Checks

  • I have searched GitHub for a duplicate issue and I'm sure this is something new
  • I have searched Google & StackOverflow for a solution and couldn't find anything
  • I have read and followed the docs and still think this is a bug
  • I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like FastAPI or mypy)

Description

Discriminator validation.

Expected: ValidationError when passing list or dict as discriminator.

Received: ConfigError.

Example Code

from typing import Literal

import pydantic


class Model1(pydantic.BaseModel):
    target: Literal["t1"]
    a: int


class Model2(pydantic.BaseModel):
    target: Literal["t2"]
    b: int


class Foo(pydantic.BaseModel):
    foo: Model1 | Model2 = pydantic.Field(discriminator="target")


# Foo(**{"foo": {"target": []}})
Foo(**{"foo": {"target": {}}})

Python, Pydantic & OS Version

pydantic version: 1.10.2
            pydantic compiled: True
                 install path: /home/.../lib/python3.10/site-packages/pydantic
               python version: 3.10.8 (main, Oct 19 2022, 10:31:59) [GCC 9.4.0]
                     platform: Linux-5.15.0-53-generic-x86_64-with-glibc2.31
     optional deps. installed: ['typing-extensions']

Affected Components

Metadata

Metadata

Assignees

Labels

bug V1Bug related to Pydantic V1.XpendingIs unconfirmed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions