Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

delete() does nothing when its restriction contains a percent sign

未關閉
#1,636 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
78/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
mysql, postgresql, python
領域
database

研究方向

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 內容生成。

描述

bug

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
平均合併
2 天 10 小時
30 天內合併 PR
12

環境準備

  • 提供 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

datajoint/datajoint-python 的其他 Issue

查看 datajoint/datajoint-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。