Unexpected warning for computed column when migrating with MariaDB
还没有人认领这个 Issue。
评估
调研方向
从 alembic/autogenerate/compare.py 第 1029 行附近开始,使用 MariaDB 计算列示例重现第二次运行 flask db migrate 的过程。比较报告中显示的元数据和连接默认值;完成的标准是,未更改的 schema 不生成警告,并且仍然报告没有 schema 更改。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
Warning is emitted when generating migration for model with computed column.
Expected behavior
No warning emitted.
To Reproduce
Code
# app.py
import os
import flask
import flask_sqlalchemy as fsa
import flask_migrate as fm
import sqlalchemy as sa
app = flask.Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = (
f'mariadb+pymysql://{os.environ['DB_USER']}:{os.environ['DB_PASSWORD']}'
'@localhost:{os.environ['DB_PORT']}/{os.environ['DB_NAME']}'
)
db = fsa.SQLAlchemy(app)
migrate = fm.Migrate(app, db)
class RecordWithComputed(db.Model):
id = sa.Column(sa.Integer, primary_key=True)
created_at = sa.Column(sa.DateTime, nullable=False)
deleted_at = sa.Column(sa.DateTime)
is_active_record = sa.Column(sa.Boolean, sa.Computed('CASE WHEN deleted_at IS NULL THEN TRUE ELSE NULL END'))
Steps to reproduce
- Create and apply first migration.
- Try creating second migration.
Error
Output for first migration
flask db migrate -m "first migration"
INFO [alembic.runtime.migration] Context impl MariaDBImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.autogenerate.compare] Detected added table 'record_with_computed'
Generating /Users/eganma/junk/computed-column-warning/migrations/versions/15d57df5db98_first_migration.py ... done
Output for second migration (no changes made to app.py)
flask db migrate -m "second migration"
INFO [alembic.runtime.migration] Context impl MariaDBImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
/Users/eganma/Library/Caches/pypoetry/virtualenvs/computed-column-warning-swI5pdsd-py3.12/lib/python3.12/site-packages/alembic/autogenerate/compare.py:1034: UserWarning: Computed default on record_with_computed.is_active_record cannot be modified
util.warn("Computed default on %s.%s cannot be modified" % (tname, cname))
INFO [alembic.env] No changes in schema detected.
Strings being compared at compare.py:1029
rendered_metadata_default = 'casewhendeleted_atisnullthentrueelsenullend'
rendered_conn_default = 'casewhendeleted_atisnullthen1elsenullend'
Versions.
- OS: macOS
- Python: 3.12.0
- Alembic: 1.14.1
- SQLAlchemy: 2.0.38
- Database: MariaDB 10.11.6
- DBAPI: pymysql 1.1.1
Additional context
Doesn't look like this is causing problems for me at this time, but previous reports I found (#1151, #1462) were focused on postgres. Issue seems to stem from TRUE being reported as the boolean equivalent 1 when comparing the model against the schema.
- 主要语言
- Python
- 星标
- 4.5k
- 派生
- 391
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
sqlalchemy/alembic 的其他 Issue
-
on_version_apply is typed as a positional callable, but alembic calls it with keyword arguments可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
sqlalchemy/alembic#1883 · 1 条评论 ·
-
Revision message is rendered unescaped into the migration docstring; triple quotes and backslashes break the generated script可能重新可做 @ApparentlyTejas 于 21 天前认领,目前没有进行中的 PR。 未关闭bug command interface
难度 2/5 1-3 小时 新手友好度 70/100
sqlalchemy/alembic#1879 · 3 条评论 ·
-
bug pep 484
难度 2/5 1-3 小时 新手友好度 74/100
sqlalchemy/alembic#1341 · 2 条评论 ·
-
autogenerate - detection bug
难度 2/5 1-3 小时 新手友好度 74/100
sqlalchemy/alembic#1121 · 3 条评论 ·
-
Identity and Computed comparison skipped when compare_server_default is not set, as of 1.18.0可能重新可做 关联的 PR 已关闭且未合并。 未关闭autogenerate - defaults bug regression
难度 3/5 1-2 天 新手友好度 50/100
sqlalchemy/alembic#1877 · 1 条评论 ·
查看 sqlalchemy/alembic 的全部 Issue
相似的 Issue
-
area:core-platform effort:S priority:P3 risk:night-safe status:ready type:test
难度 2/5 1-3 小时 新手友好度 78/100
randomparity/kdive#3620 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
FinanceFlash/unvibecode#760 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
google-research/google-research#3470 ·
维护者通常 21 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
mrvautin/ha-workouts#11 ·