Skip to content

Commit da9574d

Browse files
committed
Disable identities if blake2b is not available
Resolves #2354
1 parent 40a47fd commit da9574d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

soda/core/soda/execution/identity.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import warnings
12
from dataclasses import dataclass
23
from datetime import timedelta
3-
from hashlib import blake2b
44
from numbers import Number
55
from typing import Optional
66

7+
try:
8+
from hashlib import blake2b
9+
blake2b_available = True
10+
except ImportError:
11+
warnings.warn("The `hashlib.blake2b` hashing algorithm is not available. No identities will be generated.")
12+
blake2b_available = False
13+
714

815
class Identity:
916
@staticmethod
@@ -60,9 +67,9 @@ def __init__(self, hash_string_length: int = 8):
6067
self.hash_string_length = hash_string_length
6168
self.blake2b = None
6269

63-
def get_blake2b(self) -> blake2b:
70+
def get_blake2b(self) -> "blake2b":
6471
# Lazy initialization of blake2b in order to return None in the self.get_hash(self) in case nothing was added
65-
if self.blake2b is None:
72+
if self.blake2b is None and blake2b_available:
6673
self.blake2b = blake2b(digest_size=int(self.hash_string_length / 2))
6774
return self.blake2b
6875

@@ -73,12 +80,14 @@ def add(self, value: Optional[str]):
7380
from soda.sodacl.schema_check_cfg import SchemaValidations
7481
from soda.sodacl.threshold_cfg import ThresholdCfg
7582

76-
if value is None:
83+
blake2b = self.get_blake2b()
84+
85+
if value is None or blake2b is None:
7786
return
7887
elif isinstance(value, str):
79-
self.get_blake2b().update(value.encode("utf-8"))
88+
blake2b.update(value.encode("utf-8"))
8089
elif isinstance(value, Number) or isinstance(value, bool):
81-
self.get_blake2b().update(str(value).encode("utf-8"))
90+
blake2b.update(str(value).encode("utf-8"))
8291
elif isinstance(value, list) or isinstance(value, dict):
8392
self.add_all(value)
8493
elif isinstance(value, timedelta):

0 commit comments

Comments
 (0)