From e608b512100b1d8cf76d447391d5fb8d6a7a406f Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Wed, 7 Oct 2026 15:37:08 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E6=AD=A3=E5=88=97=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E6=96=AD=E8=A8=80=E2=80=94=E2=80=94SQLAlchemy=20?= =?UTF-8?q?=E4=BC=9A=E5=AF=B9=E4=BF=9D=E7=95=99=E5=AD=97=E5=8A=A0=E5=8F=8D?= =?UTF-8?q?=E5=BC=95=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit monitor_run.trigger 是 MySQL 保留字,渲染出来是 `trigger`。这比之前手写的列清单更正确: 清单里的裸 trigger 会直接语法错误。断言改为剥掉引号后比对列名。 --- tests/test_monitor_column_migration.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_monitor_column_migration.py b/tests/test_monitor_column_migration.py index bb1967a..b104e3d 100644 --- a/tests/test_monitor_column_migration.py +++ b/tests/test_monitor_column_migration.py @@ -34,7 +34,12 @@ def _ddl(column: Column) -> str: def test_column_renders_as_ddl(column): ddl = db._column_ddl(column) - assert ddl.startswith(column.name) + # SQLAlchemy back-quotes an identifier only when it has to, so the rendered + # name matches the column's with the quoting stripped -- which is the case for + # reserved words like monitor_run.trigger. That quoting is a feature: the + # hand-kept list this replaced would have emitted bare `trigger` and died on a + # syntax error. + assert ddl.split(" ", 1)[0].strip("`") == column.name # MySQL refuses AUTO_INCREMENT together with the DEFAULT this helper appends # to NOT NULL columns. assert "AUTO_INCREMENT" not in ddl