Skip to content

Commit 2df1056

Browse files
committed
Fix PostgresIntrospection.get_constraints crashing for PK in PostgreSQL 13.x
1 parent 2156dfe commit 2df1056

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

psqlextra/backend/introspection.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,14 @@ def get_constraints(self, cursor, table_name: str):
187187
"SELECT indexname, indexdef FROM pg_indexes WHERE tablename = %s",
188188
(table_name,),
189189
)
190-
for index, definition in cursor.fetchall():
191-
if constraints[index].get("definition") is None:
192-
constraints[index]["definition"] = definition
190+
for index_name, definition in cursor.fetchall():
191+
# PostgreSQL 13 or older won't give a definition if the
192+
# index is actually a primary key.
193+
constraint = constraints.get(index_name)
194+
if not constraint:
195+
continue
196+
197+
if constraint.get("definition") is None:
198+
constraint["definition"] = definition
193199

194200
return constraints

0 commit comments

Comments
 (0)