Opened 5 years ago

Closed 5 years ago

#30846 closed Bug (fixed)

postgis backend doesn't respect custom index names.

Reported by: Thomas Steen Rasmussen Owned by: Pratik Kumar
Component: GIS Version: dev
Severity: Normal Keywords:
Cc: Ahmad Abdallah Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Hello,

I am trying to create an index for a table with some geodjango fields. The PostGIS code doesn't take the index name into account, it always generates one based on table and field name.
Compare https://github.com/django/django/blob/master/django/contrib/gis/db/backends/postgis/schema.py#L38 with https://github.com/django/django/blob/master/django/db/backends/base/schema.py#L967 and it is clear that some logic to determine the name is missing. That leads to the following result in sqlmigrate:

    --
    -- Create index dar_navngivenvej_historik_vvnl on field(s) vejnavnebeliggenhed_vejnavnelinje of model darnavngivenvejhistorik
    --
    CREATE INDEX "dawarepl_dar_navngivenvej_historik_vejnavnebeliggenhed_vejnavnelinje_id" ON "dawarepl_dar_navngivenvej_historik"USING GIST ("vejnavnebeliggenhed_vejnavnelinje");
    --
    -- Create index dar_navngivenvej_historik_vvno on field(s) vejnavnebeliggenhed_vejnavneområde of model darnavngivenvejhistorik
    --
    CREATE INDEX "dawarepl_dar_navngivenvej_historik_vejnavnebeliggenhed_vejnavneområde_id" ON "dawarepl_dar_navngivenvej_historik"USING GIST ("vejnavnebeliggenhed_vejnavneområde");
    --
    -- Create index dar_navngivenvej_historik_vvtp on field(s) vejnavnebeliggenhed_vejtilslutningspunkter of model darnavngivenvejhistorik
    --
    CREATE INDEX "dawarepl_dar_navngivenvej_historik_vejnavnebeliggenhed_vejtilslutningspunkter_id" ON "dawarepl_dar_navngivenvej_historik"USING GIST ("vejnavnebeliggenhed_vejtilslutningspunkter");
    --

In case it isn't clear, the index names in the SQL comment are "mine" from the Meta: section of the model, but the index names used in the actual SQL are the much longer autogenerated ones.

I believe this should be fixed with a construct like https://github.com/django/django/blob/master/django/db/backends/base/schema.py#L967 so autogenerated names are only used when 'name' not in kwargs.

Change History (11)

comment:1 by Thomas Steen Rasmussen, 5 years ago

Summary: PostGIS not respecting index namesGeoDjango not respecting index names

comment:2 by Mariusz Felisiak, 5 years ago

Summary: GeoDjango not respecting index namespostgis backend doesn't respect custom index names.
Triage Stage: UnreviewedAccepted
Version: 2.2master

Thanks for the report. Agreed, we should respect Index.name for spatial indexes.

comment:3 by Claude Paroz, 5 years ago

Easy pickings: set

Tentatively set easy picking (without thorough examination).

comment:4 by Ahisahar Pretel, 5 years ago

Owner: changed from nobody to Ahisahar Pretel
Status: newassigned

I think I can take a look at this if no one started working already on this.

comment:5 by Pratik Kumar, 5 years ago

Owner: changed from Ahisahar Pretel to Pratik Kumar

This ticket seems inactive. So I am assigning it to myself

comment:6 by Pratik Kumar, 5 years ago

https://github.com/Pratik1999/django-1/tree/ticket_30846

These are the changes I have made, shall I submit the pull request? Or more changes are needed?

comment:7 by Mariusz Felisiak, 5 years ago

Pratik1999, PR is the proper place to discuss patches. At first glance, tests are missing.

comment:8 by Ahmad Abdallah, 5 years ago

Cc: Ahmad Abdallah added

comment:9 by Pratik Kumar, 5 years ago

Has patch: set

comment:10 by Mariusz Felisiak, 5 years ago

Triage Stage: AcceptedReady for checkin

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 20ba3ce4:

Fixed #30846 -- Made PostGIS backend respect Index's name argument.

Note: See TracTickets for help on using tickets.
Back to Top