From 271dc2b243e086f8cf416ac8db63255f2dca5e1d Mon Sep 17 00:00:00 2001 From: Matt Kaye Date: Mon, 14 Jul 2025 13:24:34 -0400 Subject: [PATCH] Hotfix: Allow other types in `remove_null_unicode_character` (#1988) * fix: allow any types in `remove_null_unicode_character` * chore: ver * chore: changelog * feat: tests --- sdks/python/CHANGELOG.md | 6 ++++ sdks/python/hatchet_sdk/utils/serde.py | 18 +++++----- sdks/python/pyproject.toml | 2 +- sdks/python/tests/test_serde.py | 47 ++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 sdks/python/tests/test_serde.py diff --git a/sdks/python/CHANGELOG.md b/sdks/python/CHANGELOG.md index 2901d91c0..e7224eb26 100644 --- a/sdks/python/CHANGELOG.md +++ b/sdks/python/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to Hatchet's Python SDK will be documented in this changelog The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.15.3] - 2025-07-14 + +### Changed + +- `remove_null_unicode_character` now accepts any type of data, not just strings, dictionaries, lists, and tuples. If the data is not one of these types, it's returned as-is. + ## [1.15.2] - 2025-07-12 ### Changed diff --git a/sdks/python/hatchet_sdk/utils/serde.py b/sdks/python/hatchet_sdk/utils/serde.py index 7ac1cc7d0..123d9c1d3 100644 --- a/sdks/python/hatchet_sdk/utils/serde.py +++ b/sdks/python/hatchet_sdk/utils/serde.py @@ -2,10 +2,7 @@ from typing import Any, TypeVar, cast, overload T = TypeVar("T") K = TypeVar("K") - - -@overload -def remove_null_unicode_character(data: str, replacement: str = "") -> str: ... +R = TypeVar("R") @overload @@ -24,9 +21,13 @@ def remove_null_unicode_character( ) -> tuple[T, ...]: ... +@overload +def remove_null_unicode_character(data: R, replacement: str = "") -> R: ... + + def remove_null_unicode_character( - data: str | dict[K, T] | list[T] | tuple[T, ...], replacement: str = "" -) -> str | dict[K, T] | list[T] | tuple[T, ...]: + data: dict[K, T] | list[T] | tuple[T, ...] | R, replacement: str = "" +) -> str | dict[K, T] | list[T] | tuple[T, ...] | R: """ Recursively traverse a dictionary (a task's output) and remove the unicode escape sequence \\u0000 which will cause unexpected behavior in Hatchet. @@ -36,7 +37,6 @@ def remove_null_unicode_character( :param replacement: The string to replace \\u0000 with. :return: The same dictionary with all \\u0000 characters removed from strings, and nested dictionaries/lists processed recursively. - :raises TypeError: If the input is not a string, dictionary, list, or tuple. """ if isinstance(data, str): return data.replace("\u0000", replacement) @@ -57,6 +57,4 @@ def remove_null_unicode_character( remove_null_unicode_character(cast(Any, item), replacement) for item in data ) - raise TypeError( - f"Unsupported type {type(data)}. Expected str, dict, list, or tuple." - ) + return data diff --git a/sdks/python/pyproject.toml b/sdks/python/pyproject.toml index b6a92ad48..c2570ce43 100644 --- a/sdks/python/pyproject.toml +++ b/sdks/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "hatchet-sdk" -version = "1.15.2" +version = "1.15.3" description = "" authors = ["Alexander Belanger "] readme = "README.md" diff --git a/sdks/python/tests/test_serde.py b/sdks/python/tests/test_serde.py new file mode 100644 index 000000000..80abb2170 --- /dev/null +++ b/sdks/python/tests/test_serde.py @@ -0,0 +1,47 @@ +from hatchet_sdk import remove_null_unicode_character + + +def test_remove_null_unicode() -> None: + assert remove_null_unicode_character( + {"message": "Hello\x00World", "user": "test\0user"}, + replacement=" ", + ) == { + "message": "Hello World", + "user": "test user", + } + + assert remove_null_unicode_character( + ["Hello\x00World", "test\0user"], replacement=" " + ) == [ + "Hello World", + "test user", + ] + + assert remove_null_unicode_character( + ("Hello\x00World", "test\0user"), replacement=" " + ) == ( + "Hello World", + "test user", + ) + + assert ( + remove_null_unicode_character("Hello\x00World", replacement=" ") + == "Hello World" + ) + + assert remove_null_unicode_character( + {"key": "value", "nested": {"inner": "text\0with\u0000"}}, + replacement=" ", + ) == { + "key": "value", + "nested": {"inner": "text with "}, + } + + assert remove_null_unicode_character(1) == 1 + assert remove_null_unicode_character(None) is None + assert remove_null_unicode_character(True) is True + assert remove_null_unicode_character(3.14) == 3.14 + assert remove_null_unicode_character( + {"int": 1, "float": 2.5, "string": "test\0user"}, + replacement=" ", + ) == {"int": 1, "float": 2.5, "string": "test user"}