Skip to content

Commit

Permalink
Return actual bytes instead of list of ints for BYTEA type
Browse files Browse the repository at this point in the history
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
  • Loading branch information
chandr-andr committed Oct 17, 2024
1 parent b8b846f commit 4ff39a7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "psqlpy"
version = "0.8.2"
version = "0.8.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
4 changes: 2 additions & 2 deletions python/tests/test_value_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async def test_as_class(
@pytest.mark.parametrize(
["postgres_type", "py_value", "expected_deserialized"],
(
("BYTEA", b"Bytes", [66, 121, 116, 101, 115]),
("BYTEA", b"Bytes", b"Bytes"),
("VARCHAR", "Some String", "Some String"),
("TEXT", "Some String", "Some String"),
(
Expand Down Expand Up @@ -829,7 +829,7 @@ class ValidateModelForInnerValueType(BaseModel):
some_enum: TestEnum

class ValidateModelForCustomType(BaseModel):
bytea_: List[int]
bytea_: bytes
varchar_: str
text_: str
bool_: bool
Expand Down
13 changes: 9 additions & 4 deletions src/value_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1314,10 +1314,15 @@ fn postgres_bytes_to_py(
match *type_ {
// ---------- Bytes Types ----------
// Convert BYTEA type into Vector<u8>, then into PyBytes
Type::BYTEA => Ok(_composite_field_postgres_to_py::<Option<Vec<u8>>>(
type_, buf, is_simple,
)?
.to_object(py)),
Type::BYTEA => {
let vec_of_bytes = _composite_field_postgres_to_py::<Option<Vec<u8>>>(
type_, buf, is_simple,
)?;
if let Some(vec_of_bytes) = vec_of_bytes {
return Ok(PyBytes::new_bound(py, &vec_of_bytes).to_object(py));
}
Ok(py.None())
},
// // ---------- String Types ----------
// // Convert TEXT and VARCHAR type into String, then into str
Type::TEXT | Type::VARCHAR | Type::XML => Ok(_composite_field_postgres_to_py::<Option<String>>(
Expand Down

0 comments on commit 4ff39a7

Please sign in to comment.