-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Closed
Copy link
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
This is because _enforce_dict_if_root() checks only for dicts with root key but not for models with root key.
Example Code
from pydantic import BaseModel
class Test(BaseModel):
__root__: int
Test.parse_obj(dict(Test.parse_obj(1))) # works fine
Test.parse_obj(Test.parse_obj(1))
# Expected: Test(__root__=1)
# Actual: pydantic.error_wrappers.ValidationError: 1 validation error for Test
# __root__
# value is not a valid integer (type=type_error.integer)Python, Pydantic & OS Version
pydantic version: 1.10.2
pydantic compiled: True
install path: C:\Users\gou17\AppData\Local\Programs\Python\Python310\Lib\site-packages\pydantic
python version: 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)]
platform: Windows-10-10.0.22621-SP0
optional deps. installed: ['dotenv', 'email-validator', '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.