delete() does nothing when its restriction contains a percent sign
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 78/100
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 197
- Forks
- 101
- Merge médio
- 2d 10h
- PRs com merge (30d)
- 12
Preparar o ambiente
- Inclui um Dockerfile ou arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de datajoint/datajoint-python
-
MySQL error 1143 (column-level SELECT denied) is not translated to AccessErrorTalvez já em andamento @Bhanu73120 assumiu há 7 dias. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
datajoint/datajoint-python#1586 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
len() of an expression with an empty primary key generates invalid SQLTalvez já em andamento @dimitri-yatsenko assumiu há 4 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
datajoint/datajoint-python#1581 ·
Mantenedores costumam responder em até 1 dia
-
dj.Diagram theme: make the font configurableTalvez já em andamento @dimitri-yatsenko assumiu há 3 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
datajoint/datajoint-python#1539 · 3 comentários ·
Mantenedores costumam responder em até 1 dia
-
enhancement
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 55/100
datajoint/datajoint-python#1644 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 4/5 1-2 dias Facilidade para iniciantes 68/100
datajoint/datajoint-python#1641 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de datajoint/datajoint-python
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
zach-blumenfeld/aip#13 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
nathanmarlor/foxess_modbus#1287 ·
Mantenedores costumam responder em até 4 dias
-
bug good first issue help wanted
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
OpenLakeForge/openlakeforge#498 ·
Mantenedores costumam responder em até 1 dia
-
good first issue hacktoberfest help wanted python
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 73/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 69/100
pollen-robotics/reachy_mini#1493 ·
Mantenedores costumam responder em até 1 dia