From 5484e5a3aec4c3289b5f0a450fec0aab72ef1201 Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Wed, 7 Oct 2026 16:32:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(creator):=20=E8=AF=A6=E6=83=85=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=94=A8=E4=BA=86=20MySQL=205.7=20=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=9A=84=20NULLS=20LAST?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1064 语法错误。nullslast() 是 PostgreSQL 语法,MySQL 5.7 不认;而 MySQL 把 NULL 视为比任何值都小, 所以 DESC 本身就把它排在最后,不需要额外声明。 这个 bug 只在真机上暴露:SQLite 从 3.30 起支持 NULLS LAST,本地测试环境测不出来。 --- api/creator/service.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/creator/service.py b/api/creator/service.py index 59b42e0..06e7a92 100644 --- a/api/creator/service.py +++ b/api/creator/service.py @@ -141,7 +141,10 @@ async def latest_notes(session: AsyncSession, account_id: int) -> List[Dict[str, & (CreatorNoteStat.captured_at == newest.c.captured_at), ) .where(CreatorNoteStat.account_id == account_id) - .order_by(CreatorNoteStat.publish_time.desc().nullslast()) + # 不要用 nullslast():那是 PostgreSQL 语法,MySQL 5.7 会直接抛 1064 语法错误。 + # MySQL 把 NULL 视为比任何值都小,所以 DESC 天然把未解析出发布时间的排在最后。 + # 这个 bug 只在真机上才暴露 —— SQLite 从 3.30 起支持 NULLS LAST,测试环境测不出来。 + .order_by(CreatorNoteStat.publish_time.desc()) ) ).all() return [_note_dict(row) for row in rows]