Skip to content

Commit d57a38b

Browse files
committed
Adding tests for multi-dimensional arrays
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
1 parent 126a92f commit d57a38b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/value_converter.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,22 @@ impl ToPyObject for PythonDTO {
198198
}
199199

200200
impl PythonDTO {
201+
/// Check is it possible to create serde `Value` from `PythonDTO`.
202+
#[must_use]
203+
pub fn is_available_to_serde_value(&self) -> bool {
204+
matches!(
205+
self,
206+
PythonDTO::PyNone
207+
| PythonDTO::PyBool(_)
208+
| PythonDTO::PyString(_)
209+
| PythonDTO::PyText(_)
210+
| PythonDTO::PyVarChar(_)
211+
| PythonDTO::PyIntI32(_)
212+
| PythonDTO::PyIntI64(_)
213+
| PythonDTO::PyFloat32(_)
214+
| PythonDTO::PyFloat64(_)
215+
)
216+
}
201217
/// Return type of the Array for `PostgreSQL`.
202218
///
203219
/// Since every Array must have concrete type,
@@ -270,6 +286,13 @@ impl PythonDTO {
270286
Ok(json!(vec_serde_values))
271287
}
272288
PythonDTO::PyArray(array) => Python::with_gil(|gil| {
289+
if let Some(array_elem) = array.iter().nth(0) {
290+
if !array_elem.is_available_to_serde_value() {
291+
return Err(RustPSQLDriverError::PyToRustValueConversionError(
292+
"Your value in dict isn't supported by JSON".into(),
293+
));
294+
}
295+
}
273296
let py_list = postgres_array_to_py(gil, Some(array.clone()));
274297
if let Some(py_list) = py_list {
275298
let mut vec_serde_values: Vec<Value> = vec![];

0 commit comments

Comments
 (0)