{"record":{"id":"8941e63e7a31b481","repo":"nautechsystems/nautilus_trader","slug":"effective-raw-scale-should-fit-in-priceraw","errorCode":null,"errorMessage":"effective raw scale should fit in PriceRaw","messagePattern":"effective raw scale should fit in PriceRaw","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/model/src/python/types/price.rs","lineNumber":390,"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) -> PriceRaw {\n        let scale = PriceRaw::try_from(raw_scale(self.precision))\n            .expect(\"effective raw scale should fit in PriceRaw\");\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":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/python/types/price.rs#L372-L408","documentation":"Price's Python __int__ divides the internal raw fixed-precision integer by the scale for the price's precision, computed via PriceRaw::try_from and expected to always fit. It panics only when the precision implies a scale outside PriceRaw's range, i.e. an invalid price precision outside supported bounds (0..=9 in this codebase).","triggerScenarios":"Calling int(price) on a Price constructed with an out-of-bounds precision so raw_scale(precision) doesn't fit PriceRaw.","commonSituations":"Building Price from untrusted venue metadata with extreme precision values; pyo3/FFI hand-constructed prices bypassing validation; test fixtures with fabricated precisions.","solutions":["Validate precision is within supported range before constructing Price (use Price::new / try_from_raw with checked precision)","Avoid int() on suspect Price values; use float(price) / as_f64 instead","Fix the upstream precision source rather than the conversion site"],"exampleFix":"// before\nticks = int(price)\n// after\nassert 0 <= price.precision <= 9, \"invalid price precision\"\nticks = int(price)","handlingStrategy":"type-guard","validationCode":"# Python\nassert 0 <= price.precision <= 9, \"invalid price precision\"\nticks = int(price)","typeGuard":"def safe_int(p: Price) -> int | None:\n    return int(p) if 0 <= p.precision <= 9 else None","tryCatchPattern":"try:\n    ticks = int(price)\nexcept Exception:\n    ticks = None  # fall back to float(price)","preventionTips":["Construct Price only via validated constructors so precision stays in 0..=9","Validate venue-provided precision before building Price","Prefer float(price) over int(price) unless raw ticks are needed"],"tags":["rust","python","panic","price","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"}