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:
1 parent
d251dbfe62
commit
f73a7e80a1
1 file changed
+6
-1
@@ -106,7 +106,12 @@ def handle_alertmanager(payload):
|
|||||||
return
|
return
|
||||||
now = time.monotonic()
|
now = time.monotonic()
|
||||||
key = dedupe_key(alerts)
|
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:
|
if key in _last_sent:
|
||||||
log(f"suppressed duplicate: {key[0]}")
|
log(f"suppressed duplicate: {key[0]}")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in new issue
Block a user