Skip to content

Commit 21932ca

Browse files
author
James William Pye
committed
Fix record packing.
Also, implicitly convert dictionary objects using the record's attmap.
1 parent c521c95 commit 21932ca

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

postgresql/protocol/typio.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
long-long based time I/O with noday-intervals.
3838
"""
3939
import codecs
40+
from operator import itemgetter
4041
from abc import ABCMeta, abstractmethod
4142

4243
from decimal import Decimal
@@ -89,6 +90,10 @@ def __repr__(self):
8990
class Row(tuple):
9091
"Name addressable items tuple; mapping and sequence"
9192
def __new__(subtype, iter, attmap = {}):
93+
if isinstance(iter, dict):
94+
iter = [
95+
iter.get(k) for k,_ in sorted(attmap.items(), key = itemgetter(1))
96+
]
9297
rob = tuple.__new__(subtype, iter)
9398
rob.attmap = attmap
9499
return rob
@@ -419,8 +424,12 @@ def unpack_a_record(data):
419424
)
420425

421426
def pack_a_record(data):
427+
if isinstance(data, dict):
428+
data = [
429+
data.get(k) for k,_ in sorted(attmap.items(), key = itemgetter(1))
430+
]
422431
return ts.record_pack(
423-
zip(typids, transform_record(cio, data, 0))
432+
tuple(zip(typids, transform_record(cio, data, 0)))
424433
)
425434

426435
return (pack_a_record, unpack_a_record)

0 commit comments

Comments
 (0)