delete(): Ctrl-C or end of input during a delete leaves its transaction open
Maintainer thường phản hồi trong vòng 6 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 74/100
Hướng nghiên cứu
Bắt đầu trong src/datajoint/table.py tại Table.delete(), đọc khối mở giao dịch, lời nhắc user_choice("Commit deletes?"), và try/except Exception hiện có gọi cancel_transaction(). Tái hiện bằng đoạn builtins.input được patch bằng mock, sau đó mở rộng trình xử lý để KeyboardInterrupt và EOFError cũng rollback khi transaction vẫn là True, rồi re-raise sau đó. Hoàn tất nghĩa là conn.in_transaction là False sau khi bị ngắt và các test delete hiện có vẫn pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 198
- Fork
- 103
- Merge trung bình
- 6 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 10
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của datajoint/datajoint-python
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
datajoint/datajoint-python#1703 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
datajoint/datajoint-python#1702 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
datajoint/datajoint-python#1701 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
dependencies needs-discussion
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
datajoint/datajoint-python#1687 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
bool() ignores dj.TopĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
datajoint/datajoint-python#1668 ·
Maintainer thường phản hồi trong vòng 6 ngày
Tất cả issue của datajoint/datajoint-python
Issue tương tự
-
cognition
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Suggestion]: Geonode MCP ServerĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
collabnix/awesome-mcp-lists#433 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
CrossEntropyFilter raises on zero probabilities and single-class resultsCó thể đã có người làm @NopeCharon đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Archmonger/ServeStatic#129 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 2 ngày