add_hookcall_monitoring undo breaks when called out of LIFO order
メンテナーはふだん 1 日以内に返信
@AlvaroBalbin がすでに取り組んでいます。
2026年11月3日 から。
評価
調査の方向性
Start in src/pluggy/_manager.py, at add_hookcall_monitoring() and its undo(), which restores self._inner_hookexec to a saved value. Run the reproducer from the issue, which adds monitors A and B, undoes A, then B, and prints the recorded events. enable_tracing() is built on the same function, so check it too. Done means undoing in any order removes only that monitor, repeated undo is harmless, and in-flight calls keep their original chain. Add a test for out-of-order undo next to the existing monitoring tests.
索引モデルが issue の本文から書いたものです。
説明
🤖 Written by Claude Opus 5.5 via Claude Code for the pluggy maintainers; I prompted it, it did the work, I read it.
add_hookcall_monitoring() returns an undo that restores the _inner_hookexec it saw at add time (src/pluggy/_manager.py, undo() sets self._inner_hookexec = oldcall). So undo only works in strict LIFO order:
- undoing an older monitor also removes every monitor added after it
- a later undo can bring back a monitor that was already removed
This applies to enable_tracing() too, since it is built on add_hookcall_monitoring().
Reproducer:
import pluggy
hs = pluggy.HookspecMarker("x")
hi = pluggy.HookimplMarker("x")
class S:
@hs
def h(self): ...
class P:
@hi
def h(self): return 1
pm = pluggy.PluginManager("x")
pm.add_hookspecs(S)
pm.register(P())
ev = []
def mon(label):
return pm.add_hookcall_monitoring(lambda *a: ev.append(label), lambda *a: None)
undo_a = mon("A")
undo_b = mon("B")
undo_a(); pm.hook.h(); print(ev) # [] -- expected ['B']
ev.clear()
undo_b(); pm.hook.h(); print(ev) # ['A'] -- expected []
The same thing happens on current main. pytest's own uses (--debug, pytester's HookRecorder) undo in LIFO order, so as far as we know nobody has hit this in practice.
Possible fix: keep the active (before, after) pairs in a list on the PluginManager. Each undo removes its own entry by identity, which makes repeated undo harmless, and then rebuilds _inner_hookexec from the list. Calls already in flight keep the chain they started with.
Found while reviewing #814, which fixed this with a much larger change and was closed.
- 主要言語
- Python
- スター
- 1.7k
- フォーク
- 200
- 平均マージ
- 10時間 4分
- マージ済み PR(30日)
- 13
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pytest-dev/pluggy のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 71/100
pytest-dev/pluggy#830 ·
メンテナーはふだん 1 日以内に返信
-
Plugin registry compares plugins by equality, not identity対応中かも @00200200 が 30 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
pytest-dev/pluggy#760 ·
メンテナーはふだん 1 日以内に返信
-
call_extra() drops arguments for partial callbacks対応中かも @HocVoNgThai が 9 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
pytest-dev/pluggy#817 ·
メンテナーはふだん 1 日以内に返信
-
call_historic() memorizes the caller's kwargs mapping, so later mutation changes what late plugins receive対応中かも @RonnyPfannschmidt が 21 日前に担当しました。 オープン
pytest-dev/pluggy#808 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
deprecate passing None as a plugin instance再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 30/100
pytest-dev/pluggy#790 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
pytest-dev/pluggy の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
FAIRmat-NFDI/pynxtools#861 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
NVIDIA/nsight-python#88 ·
メンテナーはふだん 1 日以内に返信
-
Criteria can pass when the deliverable is missing対応中かも @clementtisseau が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
harveyai/harvey-labs#217 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
priority/medium roadmap/v1.1.1 stakeholder/rapr type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
databrickslabs/ontos#1420 ·
メンテナーはふだん 3 日以内に返信