Skip to content

Commit

Permalink
Bugfix/signal fingerprint (#2642)
Browse files Browse the repository at this point in the history
* Fixes issue where fingerprints aren't always created
  • Loading branch information
kevgliss authored Oct 31, 2022
1 parent b264a98 commit 7b35982
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
22 changes: 17 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,28 @@
"files.insertFinalNewline": true,
"vetur.format.enable": false,
"python.formatting.provider": "black",
"python.formatting.blackArgs": ["--line-length", "100"],
"python.formatting.blackArgs": [
"--line-length",
"100"
],
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": ["--ignore=E24,W504,E501", "--verbose"],
"python.linting.flake8Args": [
"--ignore=E24,W504,E501",
"--verbose"
],
"python.testing.pytestEnabled": true,
"python.sortImports.args": ["--settings-path", "${workspaceFolder}/setup.cfg"],
"python.linting.pylintArgs": ["--rcfile", "${workspaceFolder}/setup.cfg"],
"python.sortImports.args": [
"--settings-path",
"${workspaceFolder}/setup.cfg"
],
"python.linting.pylintArgs": [
"--rcfile",
"${workspaceFolder}/setup.cfg"
],
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": false
}
}
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
Create Date: 2022-10-31 09:41:11.971654
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "34aeedc9d09a"
Expand Down
1 change: 1 addition & 0 deletions src/dispatch/signal/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def create_signal_instance(db_session: SessionLocal, signal_instance_data: dict)
case = case_service.create(db_session=db_session, case_in=case_in)

signal_instance.case = case
db_session.commit()
return case_flows.case_new_create_flow(
db_session=db_session, organization_slug=None, case_id=case.id
)
17 changes: 10 additions & 7 deletions src/dispatch/signal/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,17 @@ def create_instance(*, db_session, signal_instance_in: SignalInstanceCreate) ->
return signal_instance


def create_instance_fingerprint(tag_types, signal_instance: SignalInstance) -> str:
def create_instance_fingerprint(duplication_rule, signal_instance: SignalInstance) -> str:
"""Given a list of tag_types and tags creates a hash of their values."""
hash_values = []
if signal_instance.tags:
tag_type_names = [t.name for t in tag_types]
for tag in signal_instance.tags:
if tag.tag_type.name in tag_type_names:
hash_values.append(tag.tag_type.name)
if duplication_rule:
if signal_instance.tags:
tag_type_names = [t.name for t in duplication_rule.tag_types]
for tag in signal_instance.tags:
if tag.tag_type.name in tag_type_names:
hash_values.append(tag.tag_type.name)
else:
hash_values = signal_instance.raw.values()
else:
hash_values = signal_instance.raw.values() # fall back to creating a hash of all values

Expand All @@ -259,7 +262,7 @@ def deduplicate(
duplicate = False

# always fingerprint
fingerprint = create_instance_fingerprint(duplication_rule.tag_types, signal_instance)
fingerprint = create_instance_fingerprint(duplication_rule, signal_instance)
signal_instance.fingerprint = fingerprint
db_session.commit()

Expand Down

0 comments on commit 7b35982

Please sign in to comment.