delete() does nothing when its restriction contains a percent sign
维护者通常 4 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 78/100
调研方向
Start with the cascade implementation around Diagram.cascade() and the restriction handling in restrict(), then trace how conditions are reapplied to the fresh table. Reproduce the % cases with the issue’s Label and Use example. Done means the cascade deletes the matching row and its descendants without changing behavior for ordinary conditions or LIKE patterns, with regression tests covering both database drivers.
由索引模型根据 Issue 内容生成。
描述
Summary
A delete restricted by a condition that contains % deletes nothing. (Label & "name = '50%'").delete() returns 0 and leaves the row and its descendants in place, and so does a dict restriction such as {"name": "50%"}. dj.Diagram.cascade(seed).counts() reports 0 rows for every table, although len(seed) is 1.
A restriction's conditions are stored as compiled SQL, with every % already escaped as %% for the database driver. The cascade applies the seed's conditions again to a fresh copy of the table through restrict(), which escapes every % a second time. The condition then looks for the literal text 50%% and matches no row.
A LIKE pattern keeps working, because %% and % match the same strings there.
Nothing is deleted that should not be, but the delete silently does nothing.
Reproduction
DataJoint 2.3.4 and master, MySQL 8.0 and PostgreSQL 15:
import datajoint as dj
schema = dj.Schema("scratch_percent")
@schema
class Label(dj.Manual):
definition = """
label_id : int32
---
name : varchar(16)
"""
@schema
class Use(dj.Manual):
definition = """
-> Label
use_id : int32
"""
Label.insert([(1, "50%"), (2, "other")])
Use.insert([(1, 1), (2, 1)])
seed = Label & "name = '50%'"
print(len(seed)) # 1
print(dj.Diagram.cascade(seed).counts()) # 0 rows in each table
print(seed.delete(prompt=False)) # 0; both labels and both uses remain
Workaround
Restrict by the primary keys: (Label & seed.keys()).delete().
Expected behavior
The cascade selects the same rows as the restriction on its own: label 1 and its use.
- 主要语言
- Python
- 星标
- 197
- 派生
- 101
- 平均合并
- 3 天 8 小时
- 30 天内合并 PR
- 28
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
datajoint/datajoint-python 的其他 Issue
-
len() of an expression with an empty primary key generates invalid SQL可能已有人在做 @dimitri-yatsenko 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
datajoint/datajoint-python#1581 ·
维护者通常 4 天内回复
-
dj.Diagram theme: make the font configurable可能已有人在做 @dimitri-yatsenko 于 4 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
datajoint/datajoint-python#1539 · 3 条评论 ·
维护者通常 4 天内回复
-
enhancement
难度 4/5 3-5 天 新手友好度 55/100
datajoint/datajoint-python#1644 · 1 条评论 ·
维护者通常 4 天内回复
-
bug
难度 4/5 1-2 天 新手友好度 68/100
datajoint/datajoint-python#1641 ·
维护者通常 4 天内回复
-
A join on namesake secondary attributes raises the stale-`~lineage` error on a freshly declared schema可能已有人在做 @dimitri-yatsenko 于 4 天前认领。 未关闭bug
难度 3/5 1-2 天 新手友好度 82/100
datajoint/datajoint-python#1640 · 1 条评论 ·
维护者通常 4 天内回复
查看 datajoint/datajoint-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
CLIMADA-project/climada_python#1337 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
8go/matrix-commander#233 ·
-
documentation
难度 2/5 1-3 小时 新手友好度 66/100
-
documentation enhancement priority:high size:M
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
Validate non-divisible effective batch sizes in the Unsloth LoRA backend可能已有人在做 @debesh-biswas 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100