#29719: command inspectdb run against postgres' foreign data wrapper (fdw) 
fails to
list the foreign tables
-------------------------------------+-------------------------------------
               Reporter:  Luke       |          Owner:  Luke
                   Type:  Bug        |         Status:  assigned
              Component:  Database   |        Version:  2.1
  layer (models, ORM)                |       Keywords:
               Severity:  Normal     |  postgres,fdw,foreign data wrapper
           Triage Stage:             |      Has patch:  1
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  1
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 When running the "inspectdb" command against a postgres database with
 foreign data wrapper (fdw) tables, these foreign tables aren't listed.

 The bug arises here
 line#41 of db/backends/postgresql/introspection.py



 {{{
 SELECT c.relname, c.relkind
             FROM pg_catalog.pg_class c
             LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
             WHERE c.relkind IN ('r', 'v')
                 AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                 AND pg_catalog.pg_table_is_visible(c.oid)""")
 }}}

 pg_class.relkind stores foreign tables as "F" , so the condition
 "c.relkind in ('r','v')" is never met .

 The query must be rewritten as


 {{{
 SELECT c.relname, c.relkind
             FROM pg_catalog.pg_class c
             LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
             WHERE c.relkind IN ('r', 'v', 't')
                 AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                 AND pg_catalog.pg_table_is_visible(c.oid)""")
 }}}

 and on line#50


 {{{
 return [TableInfo(row[0], {'r': 't', 'v': 'v', 'f': 't'}.get(row[1]))
                 for row in cursor.fetchall()
                 if row[0] not in self.ignored_tables]
 }}}
 in order to map the 'f' to a table

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29719>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/056.8382b21572efd4394d18f57b10d350d9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to