Skip to content

Commit 64a5173

Browse files
committed
Supported ENUM PostgreSQL Type
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
1 parent 6514c98 commit 64a5173

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

python/tests/test_value_converter.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ async def test_deserialization_composite_into_python(
285285
await psql_pool.execute("DROP TYPE IF EXISTS all_types")
286286
await psql_pool.execute("DROP TYPE IF EXISTS inner_type")
287287
await psql_pool.execute("DROP TYPE IF EXISTS enum_type")
288-
await psql_pool.execute("CREATE TYPE inner_type AS (inner_value VARCHAR)")
289288
await psql_pool.execute("CREATE TYPE enum_type AS ENUM ('sad', 'ok', 'happy')")
289+
await psql_pool.execute("CREATE TYPE inner_type AS (inner_value VARCHAR, some_enum enum_type)")
290290
create_type_query = """
291291
CREATE type all_types AS (
292292
bytea_ BYTEA,
@@ -336,8 +336,14 @@ async def test_deserialization_composite_into_python(
336336
await psql_pool.execute(
337337
querystring=create_table_query,
338338
)
339+
340+
class TestEnum(Enum):
341+
OK = "ok"
342+
SAD = "sad"
343+
HAPPY = "happy"
344+
339345
await psql_pool.execute(
340-
querystring="INSERT INTO for_test VALUES (ROW($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, ROW($33), $34))", # noqa: E501
346+
querystring="INSERT INTO for_test VALUES (ROW($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, ROW($33, $34), $35))", # noqa: E501
341347
parameters=[
342348
b"Bytes",
343349
"Some String",
@@ -402,17 +408,14 @@ async def test_deserialization_composite_into_python(
402408
),
403409
],
404410
"inner type value",
405-
"ok",
411+
"happy",
412+
TestEnum.OK,
406413
],
407414
)
408415

409-
class TestEnum(Enum):
410-
OK = "ok"
411-
SAD = "sad"
412-
HAPPY = "happy"
413-
414416
class ValidateModelForInnerValueType(BaseModel):
415417
inner_value: str
418+
some_enum: TestEnum
416419

417420
class ValidateModelForCustomType(BaseModel):
418421
bytea_: List[int]

src/value_converter.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,6 @@ pub fn raw_bytes_data_process(
789789
postgres_bytes_to_py(py, column_type, raw_bytes_data, true)
790790
}
791791
Kind::Composite(fields) => {
792-
println!("1 {:p}", &raw_bytes_data);
793792
composite_postgres_to_py(py, fields, raw_bytes_data, custom_decoders)
794793
}
795794
Kind::Enum(_) => postgres_bytes_to_py(py, &Type::VARCHAR, raw_bytes_data, true),

0 commit comments

Comments
 (0)