Skip to content

Commit 4ff39a7

Browse files
committed
Return actual bytes instead of list of ints for BYTEA type
Signed-off-by: chandr-andr (Kiselev Aleksandr) <[email protected]>
1 parent b8b846f commit 4ff39a7

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "psqlpy"
3-
version = "0.8.2"
3+
version = "0.8.3"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

python/tests/test_value_converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async def test_as_class(
103103
@pytest.mark.parametrize(
104104
["postgres_type", "py_value", "expected_deserialized"],
105105
(
106-
("BYTEA", b"Bytes", [66, 121, 116, 101, 115]),
106+
("BYTEA", b"Bytes", b"Bytes"),
107107
("VARCHAR", "Some String", "Some String"),
108108
("TEXT", "Some String", "Some String"),
109109
(
@@ -829,7 +829,7 @@ class ValidateModelForInnerValueType(BaseModel):
829829
some_enum: TestEnum
830830

831831
class ValidateModelForCustomType(BaseModel):
832-
bytea_: List[int]
832+
bytea_: bytes
833833
varchar_: str
834834
text_: str
835835
bool_: bool

src/value_converter.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,10 +1314,15 @@ fn postgres_bytes_to_py(
13141314
match *type_ {
13151315
// ---------- Bytes Types ----------
13161316
// Convert BYTEA type into Vector<u8>, then into PyBytes
1317-
Type::BYTEA => Ok(_composite_field_postgres_to_py::<Option<Vec<u8>>>(
1318-
type_, buf, is_simple,
1319-
)?
1320-
.to_object(py)),
1317+
Type::BYTEA => {
1318+
let vec_of_bytes = _composite_field_postgres_to_py::<Option<Vec<u8>>>(
1319+
type_, buf, is_simple,
1320+
)?;
1321+
if let Some(vec_of_bytes) = vec_of_bytes {
1322+
return Ok(PyBytes::new_bound(py, &vec_of_bytes).to_object(py));
1323+
}
1324+
Ok(py.None())
1325+
},
13211326
// // ---------- String Types ----------
13221327
// // Convert TEXT and VARCHAR type into String, then into str
13231328
Type::TEXT | Type::VARCHAR | Type::XML => Ok(_composite_field_postgres_to_py::<Option<String>>(

0 commit comments

Comments
 (0)