From 06de770c4dc76a747fe49d1e142f1ed4650e48d6 Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Tue, 25 Feb 2025 15:43:35 +0800 Subject: [PATCH] Add async attrs for sqla mapped base (#528) --- backend/common/model.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/common/model.py b/backend/common/model.py index e99b6a8c..57ca8c5b 100644 --- a/backend/common/model.py +++ b/backend/common/model.py @@ -4,6 +4,7 @@ from datetime import datetime from typing import Annotated from sqlalchemy import DateTime +from sqlalchemy.ext.asyncio import AsyncAttrs from sqlalchemy.orm import DeclarativeBase, Mapped, MappedAsDataclass, declared_attr, mapped_column from backend.utils.timezone import timezone @@ -35,10 +36,11 @@ class DateTimeMixin(MappedAsDataclass): ) -class MappedBase(DeclarativeBase): +class MappedBase(AsyncAttrs, DeclarativeBase): """ - 声明性基类, 原始 DeclarativeBase 类, 作为所有基类或数据模型类的父类而存在 + 生命式基类, 作为所有基类或数据模型类的父类而存在 + `AsyncAttrs `__ `DeclarativeBase `__ `mapped_column() `__ """