delete(): Ctrl-C or end of input during a delete leaves its transaction open
Los mantenedores suelen responder en 6 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 74/100
Línea de trabajo
Comienza en src/datajoint/table.py en Table.delete(), leyendo el bloque que abre la transacción, el prompt user_choice("Commit deletes?") y el try/except Exception existente que llama a cancel_transaction(). Reproduce con el fragmento de builtins.input parcheado con mock y luego amplía el manejador para que KeyboardInterrupt y EOFError también hagan rollback cuando transaction siga siendo True, volviendo a lanzar después. Hecho significa que conn.in_transaction es False tras la interrupción y que las pruebas de delete existentes siguen pasando.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 198
- Forks
- 103
- Merge medio
- 6 d 1 h
- PR fusionados (30 d)
- 10
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de datajoint/datajoint-python
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
datajoint/datajoint-python#1703 ·
Los mantenedores suelen responder en 6 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
datajoint/datajoint-python#1702 ·
Los mantenedores suelen responder en 6 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
datajoint/datajoint-python#1701 ·
Los mantenedores suelen responder en 6 días
-
dependencies needs-discussion
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
datajoint/datajoint-python#1687 ·
Los mantenedores suelen responder en 6 días
-
bool() ignores dj.TopAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
datajoint/datajoint-python#1668 ·
Los mantenedores suelen responder en 6 días
Todos los issues de datajoint/datajoint-python
Issues similares
-
cognition
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
[Suggestion]: Geonode MCP ServerAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
collabnix/awesome-mcp-lists#433 ·
Los mantenedores suelen responder en 4 días
-
CrossEntropyFilter raises on zero probabilities and single-class resultsPosiblemente ocupada @NopeCharon la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Archmonger/ServeStatic#129 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 2 días