#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 layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
postgres,fdw,foreign data wrapper | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Luke:
Old description:
> 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
New description:
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
I patched the file and made this pull-request
https://github.com/django/django/pull/10351
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29719#comment:1>
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/071.a24a0ac8aa2c533c01fed85373c945ef%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.