File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -198,6 +198,22 @@ impl ToPyObject for PythonDTO {
198
198
}
199
199
200
200
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
+ }
201
217
/// Return type of the Array for `PostgreSQL`.
202
218
///
203
219
/// Since every Array must have concrete type,
@@ -270,6 +286,13 @@ impl PythonDTO {
270
286
Ok ( json ! ( vec_serde_values) )
271
287
}
272
288
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
+ }
273
296
let py_list = postgres_array_to_py ( gil, Some ( array. clone ( ) ) ) ;
274
297
if let Some ( py_list) = py_list {
275
298
let mut vec_serde_values: Vec < Value > = vec ! [ ] ;
You can’t perform that action at this time.
0 commit comments