relay: fix UnboundLocalError in dedupe pruning (rebind made the dict local)
Every webhook died on 'cannot access local variable _last_sent' because the prune comprehension rebound the module global inside the function. Prune in place instead.
This commit is contained in:
@@ -106,7 +106,12 @@ def handle_alertmanager(payload):
|
||||
return
|
||||
now = time.monotonic()
|
||||
key = dedupe_key(alerts)
|
||||
_last_sent = {k: v for k, v in _last_sent.items() if now - v < DEDUPE_SECONDS}
|
||||
# Prune in place: rebinding _last_sent here would make it local to this
|
||||
# function and the read above the assignment raises UnboundLocalError
|
||||
# (measured 2026-09-17: every webhook died on it).
|
||||
stale = [k for k, v in _last_sent.items() if now - v >= DEDUPE_SECONDS]
|
||||
for k in stale:
|
||||
del _last_sent[k]
|
||||
if key in _last_sent:
|
||||
log(f"suppressed duplicate: {key[0]}")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user