From c6581a40be3bb4c1e13861f0adbb3fe01f09107f Mon Sep 17 00:00:00 2001 From: Georgi Yanchev Date: Mon, 24 Jun 2019 16:13:57 -0400 Subject: [PATCH] Fixed #30644 -- Made introspection use pg_table_is_visible() instead of filtering by public schema on PostgreSQL. --- django/db/backends/postgresql/introspection.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py index dc3394dbe7..1c9c7e63a5 100644 --- a/django/db/backends/postgresql/introspection.py +++ b/django/db/backends/postgresql/introspection.py @@ -99,10 +99,9 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): JOIN pg_attrdef ad ON ad.oid = d.objid AND d.classid = 'pg_attrdef'::regclass JOIN pg_attribute col ON col.attrelid = ad.adrelid AND col.attnum = ad.adnum JOIN pg_class tbl ON tbl.oid = ad.adrelid - JOIN pg_namespace n ON n.oid = tbl.relnamespace WHERE s.relkind = 'S' AND d.deptype in ('a', 'n') - AND n.nspname = 'public' + AND pg_catalog.pg_table_is_visible(tbl.oid) AND tbl.relname = %s """, [table_name]) return [ @@ -125,7 +124,11 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): LEFT JOIN pg_class c2 ON con.confrelid = c2.oid LEFT JOIN pg_attribute a1 ON c1.oid = a1.attrelid AND a1.attnum = con.conkey[1] LEFT JOIN pg_attribute a2 ON c2.oid = a2.attrelid AND a2.attnum = con.confkey[1] - WHERE c1.relname = %s AND con.contype = 'f' + WHERE + c1.relname = %s AND + con.contype = 'f' AND + c1.relnamespace = c2.relnamespace AND + pg_catalog.pg_table_is_visible(c1.oid) """, [table_name]) return cursor.fetchall() @@ -157,9 +160,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): cl.reloptions FROM pg_constraint AS c JOIN pg_class AS cl ON c.conrelid = cl.oid - JOIN pg_namespace AS ns ON cl.relnamespace = ns.oid - WHERE ns.nspname = %s AND cl.relname = %s - """, ["public", table_name]) + WHERE cl.relname = %s AND pg_catalog.pg_table_is_visible(cl.oid) + """, [table_name]) for constraint, columns, kind, used_cols, options in cursor.fetchall(): constraints[constraint] = { "columns": columns, @@ -198,7 +200,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): LEFT JOIN pg_class c2 ON idx.indexrelid = c2.oid LEFT JOIN pg_am am ON c2.relam = am.oid LEFT JOIN pg_attribute attr ON attr.attrelid = c.oid AND attr.attnum = idx.key - WHERE c.relname = %s + WHERE c.relname = %s AND pg_catalog.pg_table_is_visible(c.oid) ) s2 GROUP BY indexname, indisunique, indisprimary, amname, exprdef, attoptions; """, [table_name])