delete() does nothing when its restriction contains a percent sign
Les mainteneurs répondent en général sous 4 jours
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 78/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Python
- Étoiles
- 197
- Forks
- 101
- Merge moyen
- 3 j 8 h
- PR mergées (30 j)
- 28
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de datajoint/datajoint-python
-
len() of an expression with an empty primary key generates invalid SQLPeut-être pris @dimitri-yatsenko l’a pris il y a 4 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
datajoint/datajoint-python#1581 ·
Les mainteneurs répondent en général sous 4 jours
-
dj.Diagram theme: make the font configurablePeut-être pris @dimitri-yatsenko l’a pris il y a 4 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
datajoint/datajoint-python#1539 · 3 commentaires ·
Les mainteneurs répondent en général sous 4 jours
-
enhancement
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
datajoint/datajoint-python#1644 · 1 commentaire ·
Les mainteneurs répondent en général sous 4 jours
-
bug
Difficulté 4/5 1-2 jours Accessibilité débutants 68/100
datajoint/datajoint-python#1641 ·
Les mainteneurs répondent en général sous 4 jours
-
A join on namesake secondary attributes raises the stale-`~lineage` error on a freshly declared schemaPeut-être pris @dimitri-yatsenko l’a pris il y a 4 jours. Ouvertebug
Difficulté 3/5 1-2 jours Accessibilité débutants 82/100
datajoint/datajoint-python#1640 · 1 commentaire ·
Les mainteneurs répondent en général sous 4 jours
Toutes les issues de datajoint/datajoint-python
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
CLIMADA-project/climada_python#1337 ·
Les mainteneurs répondent en général sous 3 jours
-
tail without reverseOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
8go/matrix-commander#233 ·
-
documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
-
documentation enhancement priority:high size:M
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour
-
Validate non-divisible effective batch sizes in the Unsloth LoRA backendPeut-être pris @debesh-biswas l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100