delete() does nothing when its restriction contains a percent sign
Maintainer antworten meist innerhalb von 4 Tagen
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 78/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Python
- Sterne
- 197
- Forks
- 101
- Ø Merge
- 3 T. 8 Std.
- Gemergte PRs (30 T.)
- 28
Entwicklungsumgebung
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus datajoint/datajoint-python
-
len() of an expression with an empty primary key generates invalid SQLEvtl. vergeben @dimitri-yatsenko hat das vor 4 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
datajoint/datajoint-python#1581 ·
Maintainer antworten meist innerhalb von 4 Tagen
-
dj.Diagram theme: make the font configurableEvtl. vergeben @dimitri-yatsenko hat das vor 4 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
datajoint/datajoint-python#1539 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 4 Tagen
-
enhancement
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 55/100
datajoint/datajoint-python#1644 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 4 Tagen
-
bug
Schwierigkeit 4/5 1-2 Tage Anfängerfreundlichkeit 68/100
datajoint/datajoint-python#1641 ·
Maintainer antworten meist innerhalb von 4 Tagen
-
A join on namesake secondary attributes raises the stale-`~lineage` error on a freshly declared schemaEvtl. vergeben @dimitri-yatsenko hat das vor 4 Tagen übernommen. Offenbug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 82/100
datajoint/datajoint-python#1640 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 4 Tagen
Alle Issues in datajoint/datajoint-python
Ähnliche Issues
-
[Bug]: IndexHandler.post crashes with HTTP 500 on malformed payloads, missing credentials, or when login is disabledEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 6 Tagen
-
Bump zizmor to 1.31.1+Offengithub_actions
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
collective/icalendar#2003 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
openzim/python-scraperlib#360 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
volcengine/OpenViking#6445 ·
Maintainer antworten meist innerhalb von 1 Tag