Skip to content

fix: honor json serialization of HPs #5164

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

Merged
merged 4 commits into from
May 9, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ def safe_deserialize(data: Any) -> Any:

This function handles the following cases:
1. If `data` is not a string, it returns the input as-is.
2. If `data` is a string and matches common boolean values ("true" or "false"),
it returns the corresponding boolean value (True or False).
3. If `data` is a JSON-encoded string, it attempts to deserialize it using `json.loads()`.
4. If `data` is a string but cannot be decoded as JSON, it returns the original string.

Expand All @@ -134,13 +132,6 @@ def safe_deserialize(data: Any) -> Any:
"""
if not isinstance(data, str):
return data

lower_data = data.lower()
if lower_data in ["true"]:
return True
if lower_data in ["false"]:
return False

try:
return json.loads(data)
except json.JSONDecodeError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ def test_safe_deserialize_not_a_string():
def test_safe_deserialize_boolean_strings():
assert safe_deserialize("true") is True
assert safe_deserialize("false") is False
assert safe_deserialize("True") is True
assert safe_deserialize("False") is False

# The below are not valid JSON booleans
assert safe_deserialize("True") == "True"
assert safe_deserialize("False") == "False"
assert safe_deserialize("TRUE") == "TRUE"
assert safe_deserialize("FALSE") == "FALSE"
assert safe_deserialize("tRuE") == "tRuE"
assert safe_deserialize("fAlSe") == "fAlSe"


def test_safe_deserialize_valid_json_string():
Expand Down