delete(): Ctrl-C or end of input during a delete leaves its transaction open
メンテナーはふだん 6 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 74/100
調査の方向性
src/datajoint/table.py の Table.delete() から始め、トランザクションを開くブロック、user_choice("Commit deletes?") プロンプト、および cancel_transaction() を呼び出す既存の try/except Exception を読んでください。mock でパッチした builtins.input スニペットで再現し、次にハンドラを広げて、transaction がまだ True のときに KeyboardInterrupt と EOFError もロールバックし、その後で再送出するようにしてください。完了とは、割り込み後に conn.in_transaction が False であり、既存の delete テストが引き続き通ることを意味します。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 198
- フォーク
- 103
- 平均マージ
- 6日 1時間
- マージ済み PR(30日)
- 10
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
datajoint/datajoint-python のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
datajoint/datajoint-python#1703 ·
メンテナーはふだん 6 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
datajoint/datajoint-python#1702 ·
メンテナーはふだん 6 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
datajoint/datajoint-python#1701 ·
メンテナーはふだん 6 日以内に返信
-
dependencies needs-discussion
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
datajoint/datajoint-python#1687 ·
メンテナーはふだん 6 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
datajoint/datajoint-python#1668 ·
メンテナーはふだん 6 日以内に返信
datajoint/datajoint-python の issue をすべて見る
似ている issue
-
cognition
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
collabnix/awesome-mcp-lists#433 ·
メンテナーはふだん 4 日以内に返信
-
CrossEntropyFilter raises on zero probabilities and single-class results対応中かも @NopeCharon が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Archmonger/ServeStatic#129 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 2 日以内に返信