Skip to content

Commit 0989b7d

Browse files
committed
Added support for just array in JSONB column
1 parent bb32bbc commit 0989b7d

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

python/tests/test_value_converter.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ async def test_as_class(
178178
JSONB([{"array": "json"}, {"one more": "test"}]),
179179
[{"array": "json"}, {"one more": "test"}],
180180
),
181+
(
182+
"JSONB",
183+
JSONB([1, "1", 1.0]),
184+
[1, "1", 1.0],
185+
),
181186
(
182187
"JSON",
183188
{
@@ -194,6 +199,11 @@ async def test_as_class(
194199
JSON([{"array": "json"}, {"one more": "test"}]),
195200
[{"array": "json"}, {"one more": "test"}],
196201
),
202+
(
203+
"JSON",
204+
JSON([1, "1", 1.0]),
205+
[1, "1", 1.0],
206+
),
197207
(
198208
"MACADDR",
199209
MacAddr6("08:00:2b:01:02:03"),

src/value_converter/models/serde_value.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,12 @@ fn serde_value_from_list(_gil: Python<'_>, bind_value: &Bound<'_, PyAny>) -> PSQ
6767
let mut result_vec: Vec<Value> = Vec::with_capacity(py_list.len());
6868

6969
for item in py_list.iter() {
70-
if item.is_instance_of::<PyDict>() {
71-
let python_dto = from_python_untyped(&item)?;
72-
result_vec.push(python_dto.to_serde_value()?);
73-
} else if item.is_instance_of::<PyList>() {
70+
if item.is_instance_of::<PyList>() {
7471
let serde_value = build_serde_value(&item)?;
7572
result_vec.push(serde_value);
7673
} else {
77-
return Err(RustPSQLDriverError::PyToRustValueConversionError(
78-
"Items in JSON array must be dicts or lists.".to_string(),
79-
));
74+
let python_dto = from_python_untyped(&item)?;
75+
result_vec.push(python_dto.to_serde_value()?);
8076
}
8177
}
8278

@@ -120,7 +116,7 @@ pub fn build_serde_value(value: &Bound<'_, PyAny>) -> PSQLPyResult<Value> {
120116
return serde_value_from_dict(value);
121117
} else {
122118
return Err(RustPSQLDriverError::PyToRustValueConversionError(
123-
"PyJSON must be dict value.".to_string(),
119+
"PyJSON must be dict or list value.".to_string(),
124120
));
125121
}
126122
})

0 commit comments

Comments
 (0)