{"record":{"id":"6ec8b7638e3b5a31","repo":"pathwaycom/pathway","slug":"wrong-iteration-limit","errorCode":null,"errorMessage":"wrong iteration limit","messagePattern":"wrong iteration limit","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/common.py","lineNumber":87,"sourceCode":"    ...   4\n    ...   5\n    ...   6\n    ...   7\n    ...   8''')\n    >>> ret = pw.iterate(collatz_transformer, iterated=tab)\n    >>> pw.debug.compute_and_print(ret, include_id=False)\n    val\n    1\n    1\n    1\n    1\n    1\n    1\n    1\n    1\n    \"\"\"\n    if iteration_limit is not None and iteration_limit < 1:\n        raise ValueError(\"wrong iteration limit\")\n    fn_spec = function_spec(func)\n    return G.add_iterate(\n        fn_spec, lambda node: node(**kwargs), iteration_limit=iteration_limit\n    )\n\n\n@check_arg_types\n@trace_user_frame\ndef apply(\n    fun: Callable,\n    *args: expr.ColumnExpression | Value,\n    **kwargs: expr.ColumnExpression | Value,\n) -> expr.ColumnExpression:\n    \"\"\"Applies function to column expressions, column-wise.\n    Output column type deduced from type-annotations of a function.\n\n    Example:\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/common.py#L69-L105","documentation":"pw.iterate() runs a function repeatedly until a fixed point, with an optional iteration_limit guarding against non-convergence. The limit must be at least 1 (None means unlimited); zero or negative limits are rejected immediately as nonsensical before the iteration graph is built.","triggerScenarios":"Calling pw.iterate(func, iteration_limit=0) or passing a negative limit, often because a variable intended as a real limit was never set (defaulted to 0) or was computed/decremented to a non-positive value.","commonSituations":"Configuration read from CLI args/env with a default of 0 meaning 'unlimited' in the user's head but not Pathway's; loops decrementing a limit variable and re-calling iterate with the exhausted value.","solutions":["Pass a positive limit: iteration_limit=100, or omit it (None) for unlimited iterations.","If 0 conventionally means 'no limit' in your config, translate it: iteration_limit=None if cfg.limit == 0 else cfg.limit.","Add validation of user-supplied limits before calling pw.iterate."],"exampleFix":"# before\npw.iterate(step, iteration_limit=0)\n\n# after\npw.iterate(step, iteration_limit=None)  # unlimited\npw.iterate(step, iteration_limit=1000)   # bounded","handlingStrategy":"validation","validationCode":"assert iteration_limit is None or iteration_limit >= 1, 'iteration_limit must be >= 1 or None'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Map config sentinel 0/None to iteration_limit=None explicitly.","Validate CLI-provided limits at parse time."],"tags":["pathway","iterate","argument-validation","configuration"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}