add_hookcall_monitoring undo breaks when called out of LIFO order
Los mantenedores suelen responder en 1 día
@AlvaroBalbin ya está trabajando en esto.
Desde el 3/11/2026.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 55/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
🤖 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.
- Lenguaje dominante
- Python
- Estrellas
- 1.7k
- Forks
- 200
- Merge medio
- 10 h 4 min
- PR fusionados (30 d)
- 13
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pytest-dev/pluggy
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 71/100
pytest-dev/pluggy#830 ·
Los mantenedores suelen responder en 1 día
-
Plugin registry compares plugins by equality, not identityPosiblemente ocupada @00200200 la tomó hace 30 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
pytest-dev/pluggy#760 ·
Los mantenedores suelen responder en 1 día
-
call_extra() drops arguments for partial callbacksPosiblemente ocupada @HocVoNgThai la tomó hace 9 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
pytest-dev/pluggy#817 ·
Los mantenedores suelen responder en 1 día
-
call_historic() memorizes the caller's kwargs mapping, so later mutation changes what late plugins receivePosiblemente ocupada @RonnyPfannschmidt la tomó hace 21 días. Abierto
pytest-dev/pluggy#808 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
deprecate passing None as a plugin instanceQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 30/100
pytest-dev/pluggy#790 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de pytest-dev/pluggy
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
FAIRmat-NFDI/pynxtools#861 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
NVIDIA/nsight-python#88 ·
Los mantenedores suelen responder en 1 día
-
Criteria can pass when the deliverable is missingPosiblemente ocupada @clementtisseau la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
harveyai/harvey-labs#217 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
priority/medium roadmap/v1.1.1 stakeholder/rapr type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
databrickslabs/ontos#1420 ·
Los mantenedores suelen responder en 3 días