From 12f320cbb49b63c3dff9cb8598e3615436f09519 Mon Sep 17 00:00:00 2001 From: shoucandanghehe Date: Tue, 14 May 2024 17:25:42 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=20PydanticTyp?= =?UTF-8?q?e=20=E8=BF=87=E6=97=A9=E5=8A=A0=E8=BD=BD=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0=E5=AD=90=E7=B1=BB=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_tetris_stats/db/models.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/nonebot_plugin_tetris_stats/db/models.py b/nonebot_plugin_tetris_stats/db/models.py index 068b983..cfda37a 100644 --- a/nonebot_plugin_tetris_stats/db/models.py +++ b/nonebot_plugin_tetris_stats/db/models.py @@ -23,9 +23,8 @@ class PydanticType(TypeDecorator): *args: Any, **kwargs: Any, ): - for i in get_model: - models.update(i()) - self.models = models + self.get_model = get_model + self._models = models super().__init__(*args, **kwargs) if PYDANTIC_V2: @@ -56,6 +55,14 @@ class PydanticType(TypeDecorator): ... raise ValueError + @property + def models(self) -> tuple[type[BaseModel], ...]: + models: set[type[BaseModel]] = set() + for i in self.get_model: + models.update(i()) + models.update(self._models) + return tuple(models) + class Bind(MappedAsDataclass, Model): id: Mapped[int] = mapped_column(init=False, primary_key=True)