Skip to content

Commit

Permalink
Fix PostgresIntrospection.get_constraints crashing for PK in PostgreS…
Browse files Browse the repository at this point in the history
…QL 13.x
  • Loading branch information
Photonios committed Apr 3, 2023
1 parent 2156dfe commit 2df1056
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions psqlextra/backend/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,14 @@ def get_constraints(self, cursor, table_name: str):
"SELECT indexname, indexdef FROM pg_indexes WHERE tablename = %s",
(table_name,),
)
for index, definition in cursor.fetchall():
if constraints[index].get("definition") is None:
constraints[index]["definition"] = definition
for index_name, definition in cursor.fetchall():
# PostgreSQL 13 or older won't give a definition if the
# index is actually a primary key.
constraint = constraints.get(index_name)
if not constraint:
continue

if constraint.get("definition") is None:
constraint["definition"] = definition

return constraints

0 comments on commit 2df1056

Please sign in to comment.