From 34f63c19f1ca3b61af90deeb035201e91ba644d7 Mon Sep 17 00:00:00 2001 From: mmikita95 Date: Tue, 12 Mar 2024 12:41:35 +0300 Subject: [PATCH 1/2] fix: casting all content values to string for CMCs --- src/streamsync/ui_manager.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/streamsync/ui_manager.py b/src/streamsync/ui_manager.py index 465283448..5b2cda546 100644 --- a/src/streamsync/ui_manager.py +++ b/src/streamsync/ui_manager.py @@ -76,6 +76,10 @@ def _create_component( else: parent_id = "root" if not parent_container else parent_container.id + # Converting all passed content values to strings + raw_content = kwargs.pop("content", {}) + content = {key: str(value) for key, value in raw_content.items()} + position: Optional[int] = kwargs.pop("position", None) is_positionless: bool = kwargs.pop("positionless", False) raw_handlers: dict = kwargs.pop("handlers", {}) @@ -88,6 +92,7 @@ def _create_component( type=component_type, parentId=parent_id, flag="cmc", + content=content, handlers=handlers, binding=binding, **kwargs From 796a17c52c7928a3e3272fc4d0aeb5778571d13a Mon Sep 17 00:00:00 2001 From: mmikita95 Date: Tue, 12 Mar 2024 14:51:52 +0300 Subject: [PATCH 2/2] fix: json.dumps for dicts instead of casting to str --- src/streamsync/ui_manager.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/streamsync/ui_manager.py b/src/streamsync/ui_manager.py index 5b2cda546..8e3517a4e 100644 --- a/src/streamsync/ui_manager.py +++ b/src/streamsync/ui_manager.py @@ -1,8 +1,9 @@ +from json import dumps as json_dumps from typing import Optional, Union from streamsync.core import base_component_tree -from streamsync.core_ui import (Component, SessionComponentTree, - UIError, current_parent_container) +from streamsync.core_ui import (Component, SessionComponentTree, UIError, + current_parent_container) class StreamsyncUI: @@ -57,6 +58,11 @@ def _prepare_binding(self, raw_binding): # TODO return raw_binding + def _prepare_value(self, value): + if isinstance(value, dict): + return json_dumps(value) + return str(value) + def _create_component( self, component_type: str, @@ -78,7 +84,7 @@ def _create_component( # Converting all passed content values to strings raw_content = kwargs.pop("content", {}) - content = {key: str(value) for key, value in raw_content.items()} + content = {key: self._prepare_value(value) for key, value in raw_content.items()} position: Optional[int] = kwargs.pop("position", None) is_positionless: bool = kwargs.pop("positionless", False)