diff --git a/pyproject.toml b/pyproject.toml index 1ad71ee..4f43d81 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "retrack" -version = "1.0.1" +version = "1.1.0" description = "A business rules engine" authors = ["Gabriel Guarisa ", "Nathalia Trotte "] license = "MIT" @@ -16,6 +16,7 @@ numpy = "^1.19.5" pydantic = "2.4.2" networkx = "^2.6.3" pandera = "^0.17.2" +unidecode = "^1.3.7" [tool.poetry.dev-dependencies] pytest = "*" diff --git a/retrack/engine/parser.py b/retrack/engine/parser.py index 064de50..0e47045 100644 --- a/retrack/engine/parser.py +++ b/retrack/engine/parser.py @@ -6,6 +6,8 @@ from retrack.utils.registry import Registry import json +from unidecode import unidecode + class Parser: def __init__( @@ -14,11 +16,15 @@ def __init__( component_registry: Registry = nodes.registry(), dynamic_registry: Registry = nodes.dynamic_registry(), validator_registry: Registry = validators.registry(), + raise_if_null_version: bool = False, + validate_version: bool = True, ): self.__graph_data = graph_data self._execution_order = None self.__components = {} self.__edges = None + self._raise_if_null_version = raise_if_null_version + self._validate_version = validate_version self._check_input_data(self.graph_data) @@ -213,19 +219,24 @@ def _set_version(self): self._version = self.graph_data.get("version", None) graph_json_content = ( - json.dumps(self.graph_data["nodes"]) + json.dumps(self.graph_data["nodes"], ensure_ascii=False) .replace(": ", ":") + .replace("\\", "") + .replace('"', "") .replace(", ", ",") - .encode("utf-8") ) - calculated_hash = hashlib.sha256(graph_json_content).hexdigest()[:10] + graph_json_content = unidecode(graph_json_content, errors="strict") + calculated_hash = hashlib.sha256(graph_json_content.encode()).hexdigest()[:10] if self.version is None: + if self._raise_if_null_version: + raise ValueError("Missing version") + self._version = f"{calculated_hash}.dynamic" else: file_version_hash = self.version.split(".")[0] - if file_version_hash != calculated_hash: + if file_version_hash != calculated_hash and self._validate_version: raise ValueError( f"Invalid version. Graph data has changed and the hash is different: {calculated_hash} != {file_version_hash}" ) diff --git a/retrack/engine/request_manager.py b/retrack/engine/request_manager.py index f3d2222..1007666 100644 --- a/retrack/engine/request_manager.py +++ b/retrack/engine/request_manager.py @@ -18,7 +18,7 @@ def __call__(self, value: typing.Any) -> typing.Any: else: return self.default - return str(value) if type(value) != str else value + return str(value) if not isinstance(value, str) else value class RequestManager: diff --git a/tests/resources/rule-of-rules.json b/tests/resources/rule-of-rules.json index 3c5aabb..23cf5d3 100644 --- a/tests/resources/rule-of-rules.json +++ b/tests/resources/rule-of-rules.json @@ -167,5 +167,5 @@ "name": "Output" } }, - "version": "8a3b4cc507.2023-10-25" + "version": "108d8ae316.2023-11-24" } \ No newline at end of file diff --git a/tests/resources/rule-with-version.json b/tests/resources/rule-with-version.json index 581fb0d..4b8dd93 100644 --- a/tests/resources/rule-with-version.json +++ b/tests/resources/rule-with-version.json @@ -164,5 +164,5 @@ "name": "Output" } }, - "version": "93df1616e7.2023-10-25" + "version": "16f78d5dd6.2023-11-24" } \ No newline at end of file diff --git a/tests/resources/to-lowercase.json b/tests/resources/to-lowercase.json index 225d5e6..7016135 100644 --- a/tests/resources/to-lowercase.json +++ b/tests/resources/to-lowercase.json @@ -114,5 +114,5 @@ "name": "Output" } }, - "version": "e7dd59c058.2023-10-25" + "version": "b91da10710.2023-11-24" } \ No newline at end of file