Opened 17 years ago
Closed 11 years ago
#6730 closed Cleanup/optimization (fixed)
postgresql_psycopg2 introspection includes views in generated models
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Normal | Keywords: | inspectdb |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
It's a little unexpected that inspectdb for psycopg2 includes views in its output. This is also inconsistent with the Oracle backend. The following patch corrects this behavior and gives me the results I expect:
Index: django/db/backends/postgresql_psycopg2/introspection.py =================================================================== --- django/db/backends/postgresql_psycopg2/introspection.py (revision 7196) +++ django/db/backends/postgresql_psycopg2/introspection.py (working copy) @@ -8,7 +8,7 @@ SELECT c.relname FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace - WHERE c.relkind IN ('r', 'v', '') + WHERE c.relkind = 'r' AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid)""") return [row[0] for row in cursor.fetchall()]
Change History (10)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
Fair enough, but psycopg and psycopg2 backends are the only backends in trunk which have this behavior - sqlite3, oracle and mysql all only return tables.
comment:3 by , 17 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
Yeah - we to be consistent here. Not sure which is correct, but being inconsistent is silly.
comment:4 by , 14 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Design decision needed → Accepted |
We should process views and make them managed models (Malcolm + Russ decision). Those backends that don't do it at the moment can be done piecemeal -- this isn't an all-or-nothing change before it goes in. But Meta.managed = True would be good here.
comment:5 by , 14 years ago
MySQL, at least version 5.1.x w/ Django 1.3.x, also returns views during inspectdb (which is the behavior I want). Though because views can be ill-defined in MySQL (refer to tables/columns that no longer exist), I filed this ticket: http://code.djangoproject.com/ticket/14098
comment:6 by , 14 years ago
Component: | django-admin.py inspectdb → Core (Management commands) |
---|
comment:7 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Cleanup/optimization |
comment:8 by , 13 years ago
Easy pickings: | unset |
---|---|
Keywords: | inspectdb added |
UI/UX: | unset |
comment:10 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
It's not clear that this is incorrect behaviour. Creating models over views isn't a bad thing (it works, providing you don't try to save()). Anybody using inspectdb is expected to examine the output and only use the models they need in any case.
I think this is probably better done as a documentation clarification than removing functionality.