Explorar el Código

pass validation of valid_parent if inheriting from valid class (#3519)

Thomas Brandého hace 11 meses
padre
commit
6709b49cfa
Se han modificado 1 ficheros con 11 adiciones y 4 borrados
  1. 11 4
      reflex/components/component.py

+ 11 - 4
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."
                     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(
                 valid_parent_list = ", ".join(
                     [f"`{v_parent}`" for v_parent in child._valid_parents]
                     [f"`{v_parent}`" for v_parent in child._valid_parents]
                 )
                 )
@@ -1153,6 +1153,13 @@ class Component(BaseComponent, ABC):
                     return True
                     return True
         return False
         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
     @classmethod
     def _iter_parent_classes_with_method(cls, method: str) -> Iterator[Type[Component]]:
     def _iter_parent_classes_with_method(cls, method: str) -> Iterator[Type[Component]]:
         """Iterate through parent classes that define a given method.
         """Iterate through parent classes that define a given method.