Consider Removing New Line Characters when Comparing Computed Constructs

未关闭 适合新手
#1,121 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
postgresql, python
领域
database

调研方向

从 alembic/autogenerate/compare.py 的第 1047-1055 行附近开始,这里会在比较前清理数据库和本地的计算子句。使用 PostgreSQL 上的多行 Computed Column 重现该问题,然后验证换行位置不同但等价的子句不再产生 computed-default warning。

由索引模型根据 Issue 内容生成。

描述

autogenerate - detection bug

I'm working with a Computed Column construct, which is really long and therefore contains line breaks for readability.

When this construct gets imported into the underlying database (Postgres in my case), the construct gets reformatted with line breaks inserted in different places.

This creates a small side-effect, where alembic now thinks that the original computed clause provided by the migration file is different to the one in the database, and therefore emits a warning.

/usr/local/lib/python3.10/site-packages/alembic/autogenerate/compare.py:1090: 
UserWarning: Computed default on ***  cannot be modified
util.warn("Computed default on %s.%s cannot be modified" % (tname, cname))

After inspecting the code, I found this method, which appears to sanitize the database computed clause as well as the local one:

https://github.com/sqlalchemy/alembic/blob/fc451e60731ad5b8d73255f0a1996e1d4e0f20de/alembic/autogenerate/compare.py#L1047-L1055

I feel that we should include line breaks in the list of tokens that should be removed before a comparison takes place, but happy to hear what thoughts you have on this.

Thanks!

主要语言
Python
星标
4.5k
派生
391
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

sqlalchemy/alembic 的其他 Issue

查看 sqlalchemy/alembic 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。