Opened 5 years ago

Closed 5 years ago

#31208 closed Bug (invalid)

Index introspection fails on Postgresql in presence of schema copy

Reported by: Shai Berger Owned by: Shai Berger
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Take a normal database schema created by Django.

Duplicate it under a different schema name (e.g. pg_dump it into a file, ALTER SCHEMA public RENAME TO other, and then psql the dump file).

Following this operation, index introspection fails -- if you look for an index for a column, it will not be found, because the introspection queries now return the columns lists doubled.

In details: For a Postgresql connection conn, the function conn.introspection.get_constraints() returns a dictionary whose keys are the constraint and index names and whose values are themselves dictionaries of information for constraints and indexes. In the situation described above, the 'columns' entry in these dictionaries has the contents ['column_name', 'column_name'] where it should have just ['column_name']. When Django code later looks for indexes for the specified columns, it compares this entry to ['column_name'], and since they are not equal, the index will not be found.

Context:

We sometimes like to take database contents from one machine and recreate the database on another.

In cases where the target database cluster already had some contents, we like to preserve it first by renaming the schema. We usually delete the renamed schema once the new schema creation completes successfully, but someone forgot it and our code which relied on the introspection erred (the schemas in our case were not exact duplicates, but similar enough).

Found this on 1.11, but the relevant code is the same on master:

Change History (1)

comment:1 by Shai Berger, 5 years ago

Resolution: invalid
Status: assignedclosed

My mistake, looked at the current code too quickly and didn't notice the changes which already fix this.

Note: See TracTickets for help on using tickets.
Back to Top