{"record":{"id":"ab888d339a8826c9","repo":"HKUDS/Vibe-Trading","slug":"conflicting-rates-for-key-indexed-key-rate-r","errorCode":null,"errorMessage":"conflicting rates for {key}: {indexed[key].rate!r} vs {entry.rate!r}","messagePattern":"conflicting rates for (.+?): (.+?) vs (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/entities/cashflow.py","lineNumber":576,"sourceCode":"        Args:\n            rates: The quotes, all against ``quote_currency``.\n            quote_currency: The reporting currency of the table.\n\n        Returns:\n            A new ``FxRateTable`` keyed by ``(base_currency, date)``.\n\n        Raises:\n            ValueError: If a member is not an ``FxRate``, two quotes collide\n                on the same ``(base_currency, date)`` with different rates,\n                or a quote's ``quote_currency`` disagrees with the table's.\n        \"\"\"\n        indexed: dict[tuple[str, date], FxRate] = {}\n        for entry in rates:\n            if not isinstance(entry, FxRate):\n                raise ValueError(f\"rates must contain FxRate, got {type(entry).__name__}\")\n            key = (entry.base_currency, entry.date)\n            if key in indexed and indexed[key].rate != entry.rate:\n                raise ValueError(\n                    f\"conflicting rates for {key}: {indexed[key].rate!r} vs \"\n                    f\"{entry.rate!r}\"\n                )\n            indexed[key] = entry\n        return cls(quote_currency=quote_currency, rates=indexed)\n\n    @classmethod\n    def from_mapping(\n        cls,\n        mapping: Mapping[tuple[str, \"date | datetime | str\"], float],\n        *,\n        quote_currency: str,\n    ) -> \"FxRateTable\":\n        \"\"\"Build a table from ``{(base_currency, date): rate}`` pairs.\n\n        Args:\n            mapping: Each value is units of ``quote_currency`` per 1 unit of\n                the key's currency, exactly as ``FxRate.rate`` defines it.","sourceCodeStart":558,"sourceCodeEnd":594,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/entities/cashflow.py#L558-L594","documentation":"from_rates indexes rates by (base_currency, date); if the same key appears twice with different rate values, the contradiction is rejected instead of silently keeping whichever came last, which would pick an arbitrary FX number.","triggerScenarios":"from_rates([FxRate('EUR','USD',d,1.0850), FxRate('EUR','USD',d,1.0900)], quote_currency='USD').","commonSituations":"Concatenating daily and intraday feeds covering the same day with revised values; duplicate rows in a CSV with one mistyped rate; re-fetching data appended to a stale list. Identical duplicates (same rate) are fine.","solutions":["Deduplicate by (base_currency, date), keeping the authoritative value (e.g. latest revision) before calling from_rates","If values disagree, investigate which source is right rather than dropping one arbitrarily","Keep only the max-date record per key when merging revision feeds"],"exampleFix":"# before\nFxRateTable.from_rates(rates, quote_currency='USD')  # rates has conflicting duplicates\n# after\nbest = {}\nfor r in rates:\n    k = (r.base_currency, r.date)\n    if k not in best or r.date >= best[k].date:\n        best[k] = r\ntable = FxRateTable.from_rates(list(best.values()), quote_currency='USD')","handlingStrategy":"validation","validationCode":"dedup = {}\nfor r in rates:\n    k = (r.base_currency, r.date)\n    if k not in dedup or r.rate == dedup[k].rate:\n        dedup[k] = r\nrates = list(dedup.values())","typeGuard":null,"tryCatchPattern":"try:\n    table = FxRateTable.from_rates(rates, quote_currency=q)\nexcept ValueError as e:\n    if 'conflicting rates' in str(e):\n        keep latest revision per key and retry","preventionTips":["Deduplicate feed merges on (base, date)","Treat rate revisions explicitly (keep last-write-wins by revision timestamp)"],"tags":["python","fx-rate","duplicate-data"],"backgroundTag":"conflicting-duplicate-values","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}