From 79f8df2270f4fdb154b6e67119d1dc718a13b06f Mon Sep 17 00:00:00 2001 From: Kenan Muric Date: Mon, 8 Aug 2022 11:43:34 +0200 Subject: [PATCH] Fixes factory default for possible streams in group instances --- nexus_constructor/model/group.py | 14 ++++++++++---- nexus_constructor/stream_fields_widget.py | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/nexus_constructor/model/group.py b/nexus_constructor/model/group.py index 5ca02f603..413a7ad89 100644 --- a/nexus_constructor/model/group.py +++ b/nexus_constructor/model/group.py @@ -27,6 +27,10 @@ CHILD_EXCLUDELIST = [TRANSFORMS_GROUP_NAME] +def create_list_of_possible_streams(): + return [module.value for module in StreamModules] + + @attr.s class Group: """ @@ -41,7 +45,7 @@ class Group: attributes = attr.ib(type=Attributes, factory=Attributes, init=False) values = None possible_stream_modules = attr.ib( - type=List[str], default=[module.value for module in StreamModules] + type=List[str], default=attr.Factory(create_list_of_possible_streams) ) _group_placeholder: bool = False @@ -181,13 +185,15 @@ def as_dict(self, error_collector: List[str]) -> Dict[str, Any]: return return_dict def set_possible_stream_modules(self, possible_stream_modules: List[str]): - self.possible_stream_modules = possible_stream_modules + self.possible_stream_modules = possible_stream_modules.copy() def get_possible_stream_modules(self) -> List[str]: - return self.possible_stream_modules + return self.possible_stream_modules.copy() def add_stream_module(self, module: str): - if module not in self.possible_stream_modules: + if module not in self.possible_stream_modules and module in [ + module.value for module in StreamModules + ]: self._modify_possible_streams(module, self.possible_stream_modules.append) def remove_stream_module(self, module: str): diff --git a/nexus_constructor/stream_fields_widget.py b/nexus_constructor/stream_fields_widget.py index 90d5056e8..08fed0d9a 100644 --- a/nexus_constructor/stream_fields_widget.py +++ b/nexus_constructor/stream_fields_widget.py @@ -675,7 +675,7 @@ def update_existing_stream_info(self, field): :param field: The stream group """ if not field: - raise TypeError("Field is NoneType when " "expecting type StreamModule.") + raise TypeError("Field is NoneType when expecting type StreamModule.") if isinstance(field, Group): field = field.children[0] if hasattr(field, "parent_node") and isinstance(field.parent_node, Group):