Opened 12 months ago
Closed 3 months ago
#35074 closed Bug (fixed)
Altering spatial_index does not actually create/drop the index
Reported by: | Mário Falcão | Owned by: | Mariusz Felisiak |
---|---|---|---|
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 )
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 (22)
comment:1 by , 12 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 12 months ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 12 months ago
Triage Stage: | Accepted → Unreviewed |
---|
comment:4 by , 12 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 , 12 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.
comment:6 by , 12 months ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:7 by , 12 months ago
Patch needs improvement: | set |
---|
comment:8 by , 6 months ago
Owner: | changed from | to
---|---|
Patch needs improvement: | unset |
PR (it is not the final fix, but something worth doing separately)
follow-up: 12 comment:11 by , 6 months ago
Owner: | removed |
---|---|
Patch needs improvement: | set |
Status: | assigned → new |
comment:12 by , 6 months ago
Owner: | set to |
---|---|
Patch needs improvement: | unset |
Status: | new → assigned |
Jacob, there is still one related cleanup waiting for a review.
comment:13 by , 6 months ago
Thanks, the PR Mariusz mentions is: https://github.com/django/django/pull/18175
comment:15 by , 5 months ago
Has patch: | unset |
---|
comment:19 by , 3 months ago
Needs tests: | set |
---|
comment:20 by , 3 months ago
Needs tests: | unset |
---|
comment:21 by , 3 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
Thanks for the report. However please don't accept your own tickets. I'll revert to unaccepted until someone else can review the report.