Skip to content

Commit 38ad33b

Browse files
committed
Ignore system and dropped attributes in composite types (#43)
1 parent 2609358 commit 38ad33b

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

asyncpg/introspection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
pg_attribute ia
2121
INNER JOIN pg_class c
2222
ON (ia.attrelid = c.oid)
23+
WHERE
24+
ia.attnum > 0 AND NOT ia.attisdropped
2325
GROUP BY
2426
c.reltype
2527
),

asyncpg/protocol/codecs/base.pyx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,14 @@ cdef class Codec:
153153

154154
if received_elem_typ != elem_typ:
155155
raise RuntimeError(
156-
'unexpected attribute data type: {}, expected {}'
157-
.format(received_elem_typ, elem_typ))
156+
'unexpected data type of composite type attribute {}: '
157+
'{!r}, expected {!r}'
158+
.format(
159+
i,
160+
TYPEMAP.get(received_elem_typ, received_elem_typ),
161+
TYPEMAP.get(elem_typ, elem_typ)
162+
)
163+
)
158164

159165
elem_len = hton.unpack_int32(buf.read(4))
160166
if elem_len == -1:

tests/test_codecs.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -867,12 +867,36 @@ async def test_composites_in_arrays(self):
867867
CREATE TABLE tab (d t[]);
868868
''')
869869

870-
await self.con.execute(
871-
'INSERT INTO tab (d) VALUES ($1)',
872-
[('a', 1)])
870+
try:
871+
await self.con.execute(
872+
'INSERT INTO tab (d) VALUES ($1)',
873+
[('a', 1)])
874+
875+
r = await self.con.fetchval('''
876+
SELECT d FROM tab
877+
''')
878+
879+
self.assertEqual(r, [('a', 1)])
880+
finally:
881+
await self.con.execute('''
882+
DROP TABLE tab;
883+
DROP TYPE t;
884+
''')
873885

874-
r = await self.con.fetchval('''
875-
SELECT d FROM tab
886+
async def test_table_as_composite(self):
887+
await self.con.execute('''
888+
CREATE TABLE tab (a text, b int);
889+
INSERT INTO tab VALUES ('1', 1);
876890
''')
877891

878-
self.assertEqual(r, [('a', 1)])
892+
try:
893+
r = await self.con.fetchrow('''
894+
SELECT tab FROM tab
895+
''')
896+
897+
self.assertEqual(r, (('1', 1),))
898+
899+
finally:
900+
await self.con.execute('''
901+
DROP TABLE tab;
902+
''')

0 commit comments

Comments
 (0)