From 2181f04a1c51a11a501efc1ffc873a24537ec131 Mon Sep 17 00:00:00 2001 From: Julien Barreau Date: Wed, 22 Jan 2025 16:43:28 +0100 Subject: [PATCH 1/2] fix(hook_collection_field): collection pk parsing on action hook --- .../agent_toolkit/utils/forest_schema/action_values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent_toolkit/forestadmin/agent_toolkit/utils/forest_schema/action_values.py b/src/agent_toolkit/forestadmin/agent_toolkit/utils/forest_schema/action_values.py index 363ee2302..cf0c25594 100644 --- a/src/agent_toolkit/forestadmin/agent_toolkit/utils/forest_schema/action_values.py +++ b/src/agent_toolkit/forestadmin/agent_toolkit/utils/forest_schema/action_values.py @@ -101,7 +101,7 @@ def value_to_forest(field: ActionField, value: Any) -> Any: elif field["type"] == ActionFieldType.COLLECTION and value: value = cast(CompositeIdAlias, value) - return "|".join(value) + return "|".join([str(v) for v in value]) elif field["type"] == ActionFieldType.FILE and value: return ForestValueConverter._make_data_uri(value) From 300d9304a5ee1977786569b43da4fd26a1f32cd3 Mon Sep 17 00:00:00 2001 From: Julien Barreau Date: Wed, 22 Jan 2025 17:03:21 +0100 Subject: [PATCH 2/2] chore: add a quick test to show the issue --- .../utils/forest_schema/test_action_values.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/agent_toolkit/tests/utils/forest_schema/test_action_values.py b/src/agent_toolkit/tests/utils/forest_schema/test_action_values.py index 29a8b2259..26541538b 100644 --- a/src/agent_toolkit/tests/utils/forest_schema/test_action_values.py +++ b/src/agent_toolkit/tests/utils/forest_schema/test_action_values.py @@ -156,6 +156,30 @@ def test_should_transform_multi_pk_into_composite(self): "1|2", ) + def test_should_parse_correctly_pks_when_they_are_integer(self): + self.assertEqual( + ForestValueConverter.value_to_forest( + { + "type": ActionFieldType.COLLECTION, + "watch_changes": False, + "label": "test_enum", + }, + [1], + ), + "1", + ) + self.assertEqual( + ForestValueConverter.value_to_forest( + { + "type": ActionFieldType.COLLECTION, + "watch_changes": False, + "label": "test_enum", + }, + [1, 2], + ), + "1|2", + ) + def test_should_transform_file_into_datauri(self): self.assertEqual( ForestValueConverter.value_to_forest(