From 6709b49cfa238cb3ab2c433ccffd4543f4cebb17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Brand=C3=A9ho?= Date: Wed, 19 Jun 2024 23:00:18 +0200 Subject: [PATCH] pass validation of valid_parent if inheriting from valid class (#3519) --- reflex/components/component.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/reflex/components/component.py b/reflex/components/component.py index 9496894a1..6223ec596 100644 --- a/reflex/components/component.py +++ b/reflex/components/component.py @@ -1022,10 +1022,10 @@ class Component(BaseComponent, ABC): f"The component `{comp_name}` only allows the components: {valid_child_list} as children. Got `{child_name}` instead." ) - if child._valid_parents and comp_name not in [ - *child._valid_parents, - *allowed_components, - ]: + if child._valid_parents and all( + clz_name not in [*child._valid_parents, *allowed_components] + for clz_name in self._iter_parent_classes_names() + ): valid_parent_list = ", ".join( [f"`{v_parent}`" for v_parent in child._valid_parents] ) @@ -1153,6 +1153,13 @@ class Component(BaseComponent, ABC): return True return False + @classmethod + def _iter_parent_classes_names(cls) -> Iterator[str]: + for clz in cls.mro(): + if clz is Component: + break + yield clz.__name__ + @classmethod def _iter_parent_classes_with_method(cls, method: str) -> Iterator[Type[Component]]: """Iterate through parent classes that define a given method.