add_hookcall_monitoring undo breaks when called out of LIFO order
I maintainer di solito rispondono entro 1 giorno
@AlvaroBalbin ci sta già lavorando.
Dal 3/11/2026.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 55/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
🤖 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.
- Lingua principale
- Python
- Stelle
- 1.7k
- Fork
- 200
- Merge medio
- 10h 4m
- PR unite (30g)
- 13
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pytest-dev/pluggy
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 71/100
pytest-dev/pluggy#830 ·
I maintainer di solito rispondono entro 1 giorno
-
Plugin registry compares plugins by equality, not identityForse già presa @00200200 l’ha presa 30 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
pytest-dev/pluggy#760 ·
I maintainer di solito rispondono entro 1 giorno
-
call_extra() drops arguments for partial callbacksForse già presa @HocVoNgThai l’ha presa 9 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
pytest-dev/pluggy#817 ·
I maintainer di solito rispondono entro 1 giorno
-
call_historic() memorizes the caller's kwargs mapping, so later mutation changes what late plugins receiveForse già presa @RonnyPfannschmidt l’ha presa 21 giorni fa. Aperta
pytest-dev/pluggy#808 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
deprecate passing None as a plugin instanceForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 30/100
pytest-dev/pluggy#790 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di pytest-dev/pluggy
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
FAIRmat-NFDI/pynxtools#861 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
NVIDIA/nsight-python#88 ·
I maintainer di solito rispondono entro 1 giorno
-
Criteria can pass when the deliverable is missingForse già presa @clementtisseau l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
harveyai/harvey-labs#217 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
priority/medium roadmap/v1.1.1 stakeholder/rapr type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
databrickslabs/ontos#1420 ·
I maintainer di solito rispondono entro 3 giorni