{"record":{"id":"f8c5a9a8c154907d","repo":"reflex-dev/reflex","slug":"the-component-comp-name-only-allows-the-compon","errorCode":null,"errorMessage":"The component `{comp_name}` only allows the components: {valid_child_list} as children. Got `{child_name}` instead.","messagePattern":"The component `(.+?)` only allows the components: (.+?) as children\\. Got `(.+?)` instead\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/components/component.py","lineNumber":1633,"sourceCode":"\n            if isinstance(child, Match):\n                for cases in child.match_cases:\n                    validate_child(cases[-1])\n                validate_child(child.default)\n\n            if self._invalid_children and child_name in self._invalid_children:\n                msg = f\"The component `{comp_name}` cannot have `{child_name}` as a child component\"\n                raise ValueError(msg)\n\n            if self._valid_children and child_name not in [\n                *self._valid_children,\n                *allowed_components,\n            ]:\n                valid_child_list = \", \".join([\n                    f\"`{v_child}`\" for v_child in self._valid_children\n                ])\n                msg = f\"The component `{comp_name}` only allows the components: {valid_child_list} as children. Got `{child_name}` instead.\"\n                raise ValueError(msg)\n\n            if child._valid_parents and all(\n                clz_name not in [*child._valid_parents, *allowed_components]\n                for clz_name in self._iter_parent_classes_names()\n            ):\n                valid_parent_list = \", \".join([\n                    f\"`{v_parent}`\" for v_parent in child._valid_parents\n                ])\n                msg = f\"The component `{child_name}` can only be a child of the components: {valid_parent_list}. Got `{comp_name}` instead.\"\n                raise ValueError(msg)\n\n        for child in children:\n            validate_child(child)\n\n    @staticmethod\n    def _get_vars_from_event_triggers(\n        event_triggers: dict[str, EventChain | Var],\n    ) -> Iterator[tuple[str, list[Var]]]:","sourceCodeStart":1615,"sourceCodeEnd":1651,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/components/component.py#L1615-L1651","documentation":"BaseState.get_value only accepts string keys (attribute names) when reading state values; any other key type raises TypeError.","triggerScenarios":"Calling `state.get_value(0)`, `state.get_value(some_var)` or any non-str key instead of `state.get_value(\"fieldname\")`.","commonSituations":"Code that treats State like a dict/sequence and passes indexes or Var objects; generic serialization helpers calling get(key) with arbitrary keys.","solutions":["Pass the attribute name as a string: `state.get_value(\"count\")","If you hold a Var, use `var._var_data.field_name` to obtain the string name first","Use `state.dict()` when you need the whole mapping"],"exampleFix":"// before\nstate.get_value(idx)\n// after\nstate.get_value(\"count\")","handlingStrategy":"type-guard","validationCode":"assert isinstance(key, str), \"get_value expects an attribute name\"","typeGuard":"def get_value_safe(state: rx.State, key: str) -> Any:\n    if not isinstance(key, str):\n        raise TypeError(\"key must be str\")\n    return state.get_value(key)","tryCatchPattern":null,"preventionTips":["Use state.dict() for bulk access","Keep keys as plain strings from field names"],"tags":["reflex","state","typeerror","key-type"],"backgroundTag":"invalid-key-type","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}