#5031·litestar

错误: 如果结构体中的字段被类型为 2 种或更多种类型的联合类型,而其中有一种类型带有 Meta,则 msgspec.Meta 会默默丢失

作者: happykust创建于 2026年9月1日更新于 2026年9月1日
标签Bug :bug:

from typing import Annotated, Union from litestar import Litestar, post from litestar.dto import MsgspecDTO from msgspec import Struct, Meta class TestStruct(Struct): text: Union[Annotated[str, Meta(description="only-str", min_length=5)], int]

@post('/hello', dto=MsgspecDTO[TestStruct]) async def hello(data: TestStruct) -> T: print(f"incoming text: {data.text}") return data.text

内容来源: litestar-org/litestar