{"record":{"id":"974802c6fbe785dd","repo":"reflex-dev/reflex","slug":"iterable-s","errorCode":null,"errorMessage":"{iterable!s}","messagePattern":"\\{iterable!s\\}","errorType":"exception","errorClass":"UntypedVarError","httpStatus":null,"severity":"error","filePath":"packages/reflex-components-core/src/reflex_components_core/core/foreach.py","lineNumber":117,"sourceCode":"            msg = (\n                f\"Could not foreach over var `{iterable!s}` of type {iterable._var_type}. \"\n                \"See https://reflex.dev/docs/library/dynamic-rendering/foreach/\"\n            )\n            raise ForeachVarError(msg)\n\n        if types.is_optional(iterable._var_type):\n            iterable = cond(iterable, iterable, [])\n\n        component = cls._create(\n            children=[],\n            iterable=iterable,\n            render_fn=render_fn,\n        )\n        try:\n            # Keep a ref to a rendered component to determine correct imports/hooks/styles.\n            component.children = [component._render().render_component()]\n        except UntypedVarError as e:\n            raise UntypedVarError(\n                iterable,\n                \"foreach\",\n                \"https://reflex.dev/docs/library/dynamic-rendering/foreach/\",\n            ).with_traceback(e.__traceback__) from None\n        return component\n\n    def _render(self) -> IterTag:\n        props = {}\n\n        render_sig = inspect.signature(self.render_fn)\n        params = list(render_sig.parameters.values())\n\n        # Validate the render function signature.\n        if len(params) == 0 or len(params) > 2:\n            msg = (\n                \"Expected 1 or 2 parameters in foreach render function, got \"\n                f\"{[p.name for p in params]}. See \"\n                \"https://reflex.dev/docs/library/dynamic-rendering/foreach/\"","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-core/src/reflex_components_core/core/foreach.py#L99-L135","documentation":"During foreach creation, Reflex renders one child eagerly to collect imports/hooks/styles. If the iterable's element type is untyped (UntypedVarError), it re-raises with the iterable, the 'foreach' context, and a docs link — the root cause is the same as errors 249/251: missing or insufficient type annotations on the iterated var.","triggerScenarios":"Foreach over a nested var whose element type resolves to untyped, e.g. rows: list[list] = [], or vars produced by untyped state operations (dict.values() on a bare-dict annotation).","commonSituations":"Nested containers annotated only at the outer level; vars returned by untyped computed vars (no return annotation on @rx.var).","solutions":["Fully annotate nested types: matrix: list[list[int]] = []","Annotate computed vars: @rx.var def items(self) -> list[str]: ...","Check the linked docs page for supported iterable types"],"exampleFix":"# before\n@rx.var\ndef rows(self):\n    return self.data.values()\n# after\n@rx.var\ndef rows(self) -> list[str]:\n    return list(self.data.values())","handlingStrategy":"type-guard","validationCode":"assert State.rows._var_type is not None and str(State.rows._var_type) != 'Any', 'fully annotate nested iterables'","typeGuard":"def fully_typed(v) -> bool:\n    import typing\n    t = getattr(v, '_var_type', None)\n    return t is not None and t is not typing.Any and 'Any' not in str(t)","tryCatchPattern":null,"preventionTips":["Annotate every nesting level (list[list[int]], dict[str, list[T]])","Give computed vars return type annotations"],"tags":["reflex","foreach","type-annotation"],"backgroundTag":"missing-type-annotation","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}