{"record":{"id":"40efdffe78633605","repo":"nautechsystems/nautilus_trader","slug":"effective-raw-scale-should-fit-in-moneyraw","errorCode":null,"errorMessage":"effective raw scale should fit in MoneyRaw","messagePattern":"effective raw scale should fit in MoneyRaw","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/model/src/python/types/money.rs","lineNumber":389,"sourceCode":"            )))\n        }\n    }\n\n    fn __neg__(&self) -> Self {\n        -*self\n    }\n\n    fn __pos__(&self) -> Self {\n        *self\n    }\n\n    fn __abs__(&self) -> Self {\n        if self.raw < 0 { -*self } else { *self }\n    }\n\n    fn __int__(&self) -> MoneyRaw {\n        let scale = MoneyRaw::try_from(raw_scale(self.currency.precision))\n            .expect(\"effective raw scale should fit in MoneyRaw\");\n        self.raw / scale\n    }\n\n    fn __float__(&self) -> f64 {\n        self.as_f64()\n    }\n\n    #[pyo3(signature = (ndigits=None))]\n    fn __round__(&self, ndigits: Option<u32>) -> Decimal {\n        self.as_decimal()\n            .round_dp_with_strategy(ndigits.unwrap_or(0), RoundingStrategy::MidpointNearestEven)\n    }\n\n    fn __repr__(&self) -> String {\n        format!(\"{self:?}\")\n    }\n\n    fn __str__(&self) -> String {","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/python/types/money.rs#L371-L407","documentation":"Money's Python __int__ divides the internal raw fixed-precision integer by the raw scale derived from the currency's precision, computing that scale with PriceRaw/MoneyRaw::try_from and expecting it to always fit. This is a can't-happen guard; it panics only if the effective scale exceeds the MoneyRaw integer type, implying a currency precision outside supported bounds.","triggerScenarios":"Calling int(money) on a Money whose currency precision implies a raw_scale that doesn't fit MoneyRaw — only possible with an invalid/corrupt currency definition precision.","commonSituations":"Custom Currency registered with a bogus precision (negative or beyond max supported); a bug in currency construction rather than normal use; passing raw ints as precision when building currencies from external metadata.","solutions":["Verify the currency's precision is a valid 0..=supported-max value (use Currency::new with sane precision)","Avoid int() on suspect Money values; use float(money) / as_f64 or money.formatted() instead","Fix the currency registration source (metadata feed, config) rather than the conversion call site"],"exampleFix":"// before\nunits = int(money)\n// after\nassert 0 <= money.currency.precision <= 16, \"invalid currency precision\"\nunits = int(money)","handlingStrategy":"type-guard","validationCode":"# Python\nassert 0 <= money.currency.precision <= 16, \"invalid currency precision\"\nunits = int(money)","typeGuard":"def safe_int(m: Money) -> int | None:\n    return int(m) if 0 <= m.currency.precision <= 16 else None","tryCatchPattern":"try:\n    units = int(money)\nexcept Exception:\n    units = None  # fall back to float(money)","preventionTips":["Register currencies only with valid precision values","Prefer float()/formatted() over int() unless raw units are needed","Validate precision in currency metadata ingestion"],"tags":["rust","python","panic","money","pyo3"],"backgroundTag":"value-out-of-range","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}