Skip to content

Commit c60c10e

Browse files
committed
Added fallback for Decimal convertion
1 parent dfbc75f commit c60c10e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/value_converter/dto/converter_impls.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::net::IpAddr;
1+
use std::{net::IpAddr, str::FromStr};
22

33
use chrono::{DateTime, FixedOffset, NaiveDate, NaiveDateTime, NaiveTime};
44
use pg_interval::Interval;
@@ -126,9 +126,12 @@ construct_extra_type_converter!(extra_types::CustomType, PythonDTO::PyCustomType
126126

127127
impl ToPythonDTO for PythonDecimal {
128128
fn to_python_dto(python_param: &pyo3::Bound<'_, PyAny>) -> PSQLPyResult<PythonDTO> {
129-
Ok(PythonDTO::PyDecimal(Decimal::from_str_exact(
130-
python_param.str()?.extract::<&str>()?,
131-
)?))
129+
let string = python_param.str()?;
130+
let string_extract = string.extract::<&str>()?;
131+
if let Ok(possible_r_decimal) = Decimal::from_str_exact(string_extract) {
132+
return Ok(PythonDTO::PyDecimal(possible_r_decimal));
133+
}
134+
Ok(PythonDTO::PyDecimal(Decimal::from_str(string_extract)?))
132135
}
133136
}
134137

0 commit comments

Comments
 (0)