Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mmh3.hash64 unicode exception with python2 #10685

Merged
merged 2 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion datadog_checks_base/datadog_checks/base/utils/db/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import mmh3

from datadog_checks.base import ensure_bytes
from datadog_checks.base.utils.serialization import json, sort_keys_kwargs

# Unicode character "Arabic Decimal Separator" (U+066B) is a character which looks like an ascii
Expand All @@ -22,7 +23,7 @@ def compute_sql_signature(normalized_query):
return None
# Note: please be cautious when changing this function as some features rely on this
# hash matching the APM resource hash generated on our backend.
return format(mmh3.hash64(normalized_query, signed=False)[0], 'x')
return format(mmh3.hash64(ensure_bytes(normalized_query), signed=False)[0], 'x')


def normalize_query_tag(query):
Expand Down
1 change: 1 addition & 0 deletions datadog_checks_base/tests/base/utils/db/test_db_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_compute_sql_signature(self):
when changes are made to the hashing algorithm. Changes to the hash can have
product impact since the backend expects consistency with the APM resource hash.
"""
assert '6db2e4f3905c3b5b' == compute_sql_signature('select * from dÒgs')
assert '11b755a835280e8e' == compute_sql_signature('select * from dogs')
assert 'd2a193f97126ad67' == compute_sql_signature('update dogs set name = ? where id = ?')

Expand Down