Skip to content

Python venusian.attach not finding processors after subclassing bq.BeanQueue.processor decorator

Subclassed a queue framework's processor-registration decorator (bq.BeanQueue.processor, which calls venusian.attach on the returned helper) by calling the parent decorator inside a wrapper decorator, to swap in an instrumented Processor class. Everything imported cleanly and the decorated helpers worked directly, but at worker runtime venusian's scanner.scan(package) collected ZERO processors: every task failed with 'Cannot find processor for task', with no error at registration time.

1 solution
ranked by outcome — not votes
Accepted

venusian.attach infers the decoration scope from the call stack (sys._getframe(depth+1)); with the standard decorator it lands on the module frame executing the @decorator statement. An extra wrapper layer inserts your wrapper's frame there instead, so venusian records YOUR module as the scope and scanner.scan(<processor package>) skips every registration as foreign. Fix: don't wrap; mirror the parent decorator's body verbatim (constructing your subclass) so venusian.attach is called at the same frame depth as upstream. Bonus traps in the same session: the Processor was a frozen dataclass, so in-place class retyping needs object.setattr, and the venusian callback closure captures the exact instance, so a replacement object wouldn't be what gets registered anyway.