Files
buildroot/support/testing/tests/package/sample_python_pydantic.py
Marcus Hoffmann e05648d133 package/python-pydantic-core: downgrade to 2.33.2 to sync with pydantic
pydantic pins an exact version of pydantic-core in it's pyproject.toml
[1]. This was missed during the last pydantic bump where pydantic-core
was erroneously updated to the latest release instead, in commit [2]
and [3].

Modify the pydantic runtime test to catch this error in the future.

[1] https://github.com/pydantic/pydantic/blob/v2.11.4/pyproject.toml#L49
[2] e1c939e426
[3] e42de820cd

Signed-off-by: Marcus Hoffmann <buildroot@bubu1.eu>
[Julien: add reference to commits introducing the issue]
Signed-off-by: Julien Olivain <ju.o@free.fr>
2025-05-28 21:57:35 +02:00

38 lines
828 B
Python

from datetime import datetime
from pydantic import BaseModel, PositiveInt
from pydantic.version import check_pydantic_core_version
# pydantic pins an exact version of pydantic core
# verify these are in sync in buildroots packaging
assert check_pydantic_core_version()
class User(BaseModel):
id: int
name: str = "John Doe"
signup_ts: datetime | None
tastes: dict[str, PositiveInt]
external_data = {
"id": 123,
"signup_ts": "2019-06-01 12:22",
"tastes": {
"wine": 9,
b"cheese": 7,
"cabbage": "1",
},
}
user = User(**external_data)
expected_user_dump = {
"id": 123,
"name": "John Doe",
"signup_ts": datetime(2019, 6, 1, 12, 22),
"tastes": {"wine": 9, "cheese": 7, "cabbage": 1},
}
assert user.id == 123
assert user.model_dump() == expected_user_dump