#17785: PostgreSQL Introspection: get_relations() broken after drop column
-------------------------------------+-------------------------------------
Reporter: guettli | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.3
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: psycopg2 | Needs documentation: 0
introspection | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by akaariai):
* needs_better_patch: 0 => 1
Comment:
The attached tests will not work on MySQL. The tests use fixed quoting
(not every database uses " for quoting). In addition, I don't think the
table creation belongs into the test, if at all possible it would be
better to use normal models and then alter those dynamically. This would
give better portability.
Instead of doing selects to the local and remote table in get_relations(),
we could likely use information_schema.columns to skip the missing field
indexes. The query is something like:
{{{
WITH augmented_information_schema_columns AS (
SELECT table_name, ordinal_position,
row_number() OVER (PARTITION BY table_name ORDER BY
ordinal_position)
FROM information_schema.columns
)
SELECT aisc1.row_number - 1 as local_field_index, aisc2.row_number - 1 as
remote_field_index, c2.relname
FROM pg_constraint con
JOIN pg_class c1 ON c1.oid = con.conrelid
JOIN pg_class c2 ON c2.oid = con.confrelid
JOIN augmented_information_schema_columns aisc1 ON con.conkey[1] =
aisc1.ordinal_position
AND aisc1.table_name = c1.relname
JOIN augmented_information_schema_columns aisc2 ON con.confkey[1] =
aisc2.ordinal_position
AND aisc2.table_name = c2.relname
WHERE c1.relname = 'bar'
AND con.contype = 'f';
}}}
(only very quickly tested).
Maybe a better approach would be to dump usage of column numbers
altogether, instead use just column names in get_relations().
--
Ticket URL: <https://code.djangoproject.com/ticket/17785#comment:8>
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/065.5828ff4814a81b5e2a79a355410f6bc8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.