delete(): Ctrl-C or end of input during a delete leaves its transaction open
Mantenedores costumam responder em até 6 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 74/100
Direção de pesquisa
Comece em src/datajoint/table.py em Table.delete(), lendo o bloco que abre a transação, o prompt user_choice("Commit deletes?") e o try/except Exception existente que chama cancel_transaction(). Reproduza com o snippet de builtins.input com mock patch, depois amplie o manipulador para que KeyboardInterrupt e EOFError também façam rollback quando transaction ainda for True, relançando depois. Pronto significa que conn.in_transaction é False após a interrupção e que os testes de delete existentes continuam passando.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Summary
Table.delete() with prompt=True runs the deletes inside its transaction and then asks "Commit deletes?" (src/datajoint/table.py, the user_choice("Commit deletes?", default="no") call). The question is asked after the try/except Exception that rolls the transaction back on errors. If the user presses Ctrl-C at the prompt (KeyboardInterrupt), or input ends (EOFError, for example a script run without a terminal), nothing rolls the transaction back, and the connection stays in it.
The same happens for a KeyboardInterrupt during the delete loop, with or without the prompt, since except Exception does not catch it.
Reproduced on master with MySQL 8.0 and PostgreSQL 15.
Consequences
On the same connection afterwards:
delete(prompt=True)raises "Delete cannot use a transaction within an ongoing transaction".delete(prompt=False)joins the stale transaction (it setstransaction=Falsewhen one is open), deletes the rows, logs "Delete completed", and returns their count. Inserts join it too.- None of this is committed. It is lost when the connection closes or the transaction rolls back, including the rollback done by the next
with conn.transaction:block, which raises "Nested connections are not supported." Nothing tells the user. An explicitconn.commit_transaction()would instead commit the delete the user never confirmed. - The transaction holds the locks taken by the deletes until it ends. Another session that writes those rows waits and then fails with a lock timeout (MySQL error 1205, PostgreSQL
LockNotAvailable).
Reproduce
import datajoint as dj
from unittest import mock
schema = dj.Schema("delete_prompt_demo")
@schema
class Subject(dj.Manual):
definition = """
subject_id : int32
"""
Subject.insert([(1,), (2,), (3,)])
conn = Subject.connection
with mock.patch("builtins.input", side_effect=KeyboardInterrupt):
try:
(Subject & {"subject_id": 1}).delete(prompt=True)
except KeyboardInterrupt:
pass
print(conn.in_transaction) # True: the transaction is still open
print((Subject & {"subject_id": 2}).delete(prompt=False)) # joins it: 1
conn.close()
conn.connect()
print(Subject.fetch("subject_id")) # [1 2 3]: neither delete was committed
Fix
Roll back on any exit other than a confirmed commit: wrap the delete loop and the prompt in try/except BaseException (or finally) that calls cancel_transaction() when delete() opened the transaction and did not commit, then re-raises. transaction is still True at that point only when delete() opened the transaction itself, so it is the right guard.
- Linguagem predominante
- Python
- Estrelas
- 198
- Forks
- 103
- Merge médio
- 6d 1h
- PRs com merge (30d)
- 10
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
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
datajoint/datajoint-python#1703 ·
Mantenedores costumam responder em até 6 dias
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
datajoint/datajoint-python#1702 ·
Mantenedores costumam responder em até 6 dias
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
datajoint/datajoint-python#1701 ·
Mantenedores costumam responder em até 6 dias
-
dependencies needs-discussion
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
datajoint/datajoint-python#1687 ·
Mantenedores costumam responder em até 6 dias
-
bool() ignores dj.TopAbertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
datajoint/datajoint-python#1668 ·
Mantenedores costumam responder em até 6 dias
Todas as issues de datajoint/datajoint-python
Issues semelhantes
-
cognition
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 78/100
collabnix/awesome-mcp-lists#433 ·
Mantenedores costumam responder em até 4 dias
-
CrossEntropyFilter raises on zero probabilities and single-class resultsTalvez já em andamento @NopeCharon assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Archmonger/ServeStatic#129 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 2 dias