fix(keep-provider): don't mutate the shared fingerprint_fields list - #6720
Merged
shahargl merged 1 commit intoAug 22, 2026
Merged
Conversation
_build_alert called fingerprint_fields.append("workflowId") on whatever
list was passed in. _notify_alert's per-alert loop passes the same list
object into _build_alert on every iteration of a foreach batch, so each
alert after the first accumulated one more duplicate "workflowId" entry,
changing its computed fingerprint.
Build a new list instead of appending in place, and switch the mutable
default argument to None while at it.
Fixes keephq#6719
Prabal864
force-pushed
the
fix/keep-provider-fingerprint-mutation
branch
from
August 21, 2026 20:57
fabc6ec to
1f9e634
Compare
Contributor
|
🔥 Fantastic work @Prabal864! Your very first PR to keep has been merged! 🎉🥳 You've just taken your first step into open-source, and we couldn't be happier to have you onboard. 🙌 For any support, feel free to reach out on the community: https://slack.keephq.dev. Happy coding! 👩💻👨💻 |
This was referenced Aug 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #6719.
KeepProvider._build_alertdidfingerprint_fields.append("workflowId")on whatever list was passed in._notify_alert's per-alert loop passes that same list object into_build_alerton every iteration of aforeachbatch, so each alert after the first accumulated one more duplicate"workflowId"entry, which changes its computed SHA-256 fingerprint.Fix
keep_provider.py:177- build a new list (fingerprint_fields + ["workflowId"]) instead of mutating the caller's list with.append.keep_provider.py:139- switched the mutable default argument (fingerprint_fields=[]) toNonewhile touching this line, sinceif not fingerprint_fields:already treatsNone/[]identically, so this is a no-op behaviorally but removes the classic mutable-default footgun flagged alongside the main bug.Testing
Added
tests/test_keep_provider_fingerprint_fields_mutation.py:test_build_alert_does_not_mutate_caller_fingerprint_fields- calls_build_alert3x with the samefingerprint_fieldslist (mirroring_notify_alert's loop) and asserts the list is unchanged afterward.test_build_alert_produces_consistent_fingerprints_across_a_batch- asserts an alert's fingerprint is identical whether it's built standalone or as the 3rd alert in a batch that reused the samefingerprint_fieldsobject.I wasn't able to run the full suite in my sandbox -
pip install -e .fails on this platform becauseuvloopdoesn't support Windows (a pyproject dependency), andtests/conftest.pyneeds Docker/MySQL fixtures at collection time regardless of which test is targeted. I verified both the bug and the fix by extracting the exact control flow (_build_alert's fingerprint-fields handling and the realBaseProvider.get_alert_fingerprinthashing algorithm) into a standalone script and running it directly - before the fix, a 3-alert batch leftfingerprint_fieldsas['labels.service', 'workflowId', 'workflowId', 'workflowId']and alert 3's fingerprint didn't match the correct value; after the fix, the list stays['labels.service']and the fingerprint matches.python -m py_compileandblack --check/isort --checkpass on both changed files.