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 分钟
- 30 天内合并 PR
- 13
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 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 天内回复