-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
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
- Compatibility between releases
- Data validation/parsing
- Data serialization -
.dict()and.json() - JSON Schema
- Dataclasses
- Model Config
- Field Types - adding or changing a particular data type
- Function validation decorator
- Generic Models
- Other Model behaviour -
construct(), pickling, private attributes, ORM mode - Plugins and integration with other tools - mypy, FastAPI, python-devtools, Hypothesis, VS Code, PyCharm, etc.