Opened 11 months ago

Last modified 2 months ago

#35074 closed Bug

Altering spatial_index does not actually create/drop the index — at Version 5

Reported by: Mário Falcão Owned by: Mário Falcão
Component: GIS Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mário Falcão)

Changing spatial_index on existing spatial fields causes migrations to be generated as expected, but they do not actually drop/create the indexes as desired when applied.

E.g. starting with the following model

class LocationUpdate(models.Model):
    location = PointField(geography=True, spatial_index=False)

If we change spatial_index to True, a migration is generated with a single operation:

migrations.AlterField(
    model_name="locationupdate",
    name="location",
    field=django.contrib.gis.db.models.fields.PointField(
        geography=True, srid=4326
    ),
)

But applying this migration does not create the expected index and the output of sqlmigrate is as follows:

BEGIN;
--
-- Alter field location on locationupdate
--
-- (no-op)
COMMIT;

Detected on Django 4.2.8 with PostGIS, but also present on latest main branch across all backends.

Change History (5)

comment:1 by Mário Falcão, 11 months ago

Owner: changed from nobody to Mário Falcão
Status: newassigned

comment:2 by Mário Falcão, 11 months ago

Triage Stage: UnreviewedAccepted

comment:3 by David Smith, 11 months ago

Triage Stage: AcceptedUnreviewed

Thanks for the report. However please don't accept your own tickets. I'll revert to unaccepted until someone else can review the report.

comment:4 by Mário Falcão, 11 months ago

Has patch: set
Patch needs improvement: set

Got it. FYI I am working on a patch: https://github.com/django/django/pull/17662

It properly fixed this on PostGIS but the issue appears to also be present on MySQL as the tests I added fail there. I'll improve it and post an update here when it's ready.

comment:5 by Mário Falcão, 11 months ago

Description: modified (diff)
Patch needs improvement: unset

Turns out that none of the GIS backends handled this and I believe they never did.

My patch is now ready for review - it should fix this on PostGIS, MySQL and Oracle. Spatialite is not implemented as it does not support altering geo fields.

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