add_hookcall_monitoring undo breaks when called out of LIFO order
Maintainer thường phản hồi trong vòng 1 ngày
@AlvaroBalbin đang làm issue này rồi.
Từ ngày 3/11/2026.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
🤖 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.
- Ngôn ngữ chính
- Python
- Star
- 1.7k
- Fork
- 200
- Merge trung bình
- 10 giờ 4 phút
- Pull request đã merge (30 ngày)
- 13
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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 pytest-dev/pluggy
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 71/100
pytest-dev/pluggy#830 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Plugin registry compares plugins by equality, not identityCó thể đã có người làm @00200200 đã nhận 30 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
pytest-dev/pluggy#760 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
call_extra() drops arguments for partial callbacksCó thể đã có người làm @HocVoNgThai đã nhận 9 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
pytest-dev/pluggy#817 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
call_historic() memorizes the caller's kwargs mapping, so later mutation changes what late plugins receiveCó thể đã có người làm @RonnyPfannschmidt đã nhận 21 ngày trước. Đang mở
pytest-dev/pluggy#808 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
deprecate passing None as a plugin instanceCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 30/100
pytest-dev/pluggy#790 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của pytest-dev/pluggy
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
FAIRmat-NFDI/pynxtools#861 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
NVIDIA/nsight-python#88 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Criteria can pass when the deliverable is missingCó thể đã có người làm @clementtisseau đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
harveyai/harvey-labs#217 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
priority/medium roadmap/v1.1.1 stakeholder/rapr type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
databrickslabs/ontos#1420 ·
Maintainer thường phản hồi trong vòng 3 ngày