{"record":{"id":"c7ac3606b186b177","repo":"HKUDS/Vibe-Trading","slug":"flows-index-has-no-currency-and-no-top-level-cu","errorCode":null,"errorMessage":"flows[{index}] has no currency and no top-level currency was given; currency is never defaulted","messagePattern":"flows\\[(.+?)\\] has no currency and no top-level currency was given; currency is never defaulted","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/tools/cashflow_analytics_tool.py","lineNumber":383,"sourceCode":"            default_kind=kwargs.get(\"flows_default_kind\"),\n            date_format=kwargs.get(\"flows_date_format\"),\n            invert_sign=bool(kwargs.get(\"flows_invert_sign\", False)),\n        )\n\n    if not inline:\n        return None\n    if not isinstance(inline, list):\n        raise ValueError(\"flows must be an array of {date, amount, kind} objects\")\n    if len(inline) > _MAX_INLINE_FLOWS:\n        raise ValueError(f\"flows may contain at most {_MAX_INLINE_FLOWS} entries\")\n\n    records: list[CashFlow] = []\n    for index, item in enumerate(inline):\n        if not isinstance(item, dict):\n            raise ValueError(f\"flows[{index}] must be an object\")\n        row_currency = item.get(\"currency\") or currency\n        if not row_currency:\n            raise ValueError(\n                f\"flows[{index}] has no currency and no top-level currency was \"\n                \"given; currency is never defaulted\"\n            )\n        try:\n            records.append(\n                CashFlow(\n                    date=item[\"date\"],\n                    amount=item[\"amount\"],\n                    kind=item[\"kind\"],\n                    currency=row_currency,\n                )\n            )\n        except KeyError as exc:\n            raise ValueError(f\"flows[{index}] is missing {exc.args[0]!r}\") from exc\n        except ValueError as exc:\n            raise ValueError(f\"flows[{index}]: {exc}\") from exc\n    return CashFlowSeries(tuple(records))\n","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/tools/cashflow_analytics_tool.py#L365-L401","documentation":"Currency is required per cash flow and is never defaulted. A flow must carry a non-empty 'currency' field, or a top-level currency argument must be supplied; if both are absent this indexed error is raised. This prevents silently mixing or inventing currencies in financial calculations.","triggerScenarios":"flows=[{\"date\": ..., \"amount\": ..., \"kind\": ...}] with no per-item currency and no kwargs['currency']; currency=None or currency=\"\" at top level.","commonSituations":"Assuming a default like USD exists; configs where currency is only conditionally set (currency=os.getenv(\"CURRENCY\") returning None); mixed-currency datasets where only some rows carry currency.","solutions":["Pass a top-level currency (e.g. execute(..., currency=\"USD\")) when all flows share one currency","Add 'currency' to each flow dict for mixed-currency data","Ensure env-var lookups have a real fallback value, not None"],"exampleFix":"# before\nexecute(flows=flows)\n# after\nexecute(flows=flows, currency=\"EUR\")","handlingStrategy":"validation","validationCode":"currency = kwargs.get(\"currency\") or \"USD\"  # explicit choice\nfor f in flows:\n    f.setdefault(\"currency\", currency)\nif not all(f.get(\"currency\") for f in flows):\n    raise ValueError(\"currency required per flow\")","typeGuard":"def has_currency(item: dict, top_currency: str | None) -> bool:\n    return bool(item.get(\"currency\") or top_currency)","tryCatchPattern":null,"preventionTips":["Set a top-level currency for single-currency datasets","Give env-based currency config a concrete default"],"tags":["cashflow-analytics","currency","required-field-missing","python"],"backgroundTag":"required-field-missing","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}