#30644: Some Postgres introspection methods don't filter on schema
------------------------------------------+------------------------
Reporter: Georgi Yanchev | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
Several instances of my Django application share the same Postgres
database (each in own schema). To specify which schema to use I have in my
Django settings:
{{{
DATABASES[default']['OPTIONS'] = {
'options': '-c
search_path={}'.format(get_env('POSTGRES_SCHEMA', 'public')),
}
}}}
The problem is that migrations fail, because methods like
`get_constraints` return constraints from other schemas:
https://github.com/django/django/blob/a3417282ac0464a9a2d1d7685bcfef10feed2597/django/db/backends/postgresql/introspection.py#L145
When I look deeper into that code, it looks that there is a mess with
schemas filtering.
1. The first SQL query in `get_constraints` will use hardcoded schema name
`public`:
https://github.com/django/django/blob/a3417282ac0464a9a2d1d7685bcfef10feed2597/django/db/backends/postgresql/introspection.py#L175
2. The second SQL in the same method doesn't filter by schema name, so it
will return entries from all schemas:
https://github.com/django/django/blob/a3417282ac0464a9a2d1d7685bcfef10feed2597/django/db/backends/postgresql/introspection.py#L214
3. `get_table_list` properly filters by using
`pg_catalog.pg_table_is_visible`.
4. `get_sequences` and `get_relations` will return entries from all
schemas.
--
Ticket URL: <https://code.djangoproject.com/ticket/30644>
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/057.c9ba92cda7d9fc69aa23a208a2f5ca9b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.