[Django] #35074: Altering spatial_index does not actually create/drop the index

23 views
Skip to first unread message

Django

unread,
Dec 30, 2023, 1:16:55 PM12/30/23
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
----------------------------------------+------------------------
Reporter: Mário Falcão | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 4.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 |
----------------------------------------+------------------------
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 (`manage.py sqlmigrate` reports them as no-ops).

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

--
Ticket URL: <https://code.djangoproject.com/ticket/35074>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 30, 2023, 1:17:16 PM12/30/23
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
------------------------------+----------------------------------------
Reporter: Mário Falcão | Owner: Mário Falcão
Type: Bug | Status: assigned
Component: GIS | Version: 4.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Mário Falcão):

* owner: nobody => Mário Falcão
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:1>

Django

unread,
Dec 30, 2023, 1:18:23 PM12/30/23
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
------------------------------+----------------------------------------
Reporter: Mário Falcão | Owner: Mário Falcão
Type: Bug | Status: assigned
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Mário Falcão):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:2>

Django

unread,
Dec 30, 2023, 1:48:15 PM12/30/23
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
------------------------------+----------------------------------------
Reporter: Mário Falcão | Owner: Mário Falcão
Type: Bug | Status: assigned
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by David Smith):

* stage: Accepted => Unreviewed


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:3>

Django

unread,
Dec 30, 2023, 1:57:25 PM12/30/23
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
------------------------------+----------------------------------------
Reporter: Mário Falcão | Owner: Mário Falcão
Type: Bug | Status: assigned
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Mário Falcão):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:4>

Django

unread,
Dec 30, 2023, 9:31:51 PM12/30/23
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
------------------------------+----------------------------------------
Reporter: Mário Falcão | Owner: Mário Falcão
Type: Bug | Status: assigned
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Mário Falcão):

* needs_better_patch: 1 => 0


Old description:

> 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 (`manage.py sqlmigrate` reports them as
> no-ops).
>
> Detected on Django 4.2.8 with PostGIS, but also present on latest main
> branch.

New description:

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.

--

Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:5>

Django

unread,
Jan 1, 2024, 12:04:07 PMJan 1
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
------------------------------+----------------------------------------
Reporter: Mário Falcão | Owner: Mário Falcão
Type: Bug | Status: assigned
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:6>

Django

unread,
Jan 8, 2024, 3:58:00 AMJan 8
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
------------------------------+----------------------------------------
Reporter: Mário Falcão | Owner: Mário Falcão
Type: Bug | Status: assigned
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:7>

Django

unread,
Jun 19, 2024, 6:40:09 AM (10 days ago) Jun 19
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
------------------------------+--------------------------------------------
Reporter: Mário Falcão | Owner: Mariusz Felisiak
Type: Bug | Status: assigned
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0
* owner: Mário Falcão => Mariusz Felisiak

Comment:

[https://github.com/django/django/pull/18281 PR] (it is not the final fix,
but something worth doing separately)
--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:8>

Django

unread,
Jun 20, 2024, 5:44:55 AM (9 days ago) Jun 20
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
------------------------------+--------------------------------------------
Reporter: Mário Falcão | Owner: Mariusz Felisiak
Type: Bug | Status: assigned
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"20c2d625d3d5062e43918d1d7b6f623202491dd4" 20c2d62]:
{{{#!CommitTicketReference repository=""
revision="20c2d625d3d5062e43918d1d7b6f623202491dd4"
Refs #35074 -- Avoided failed attempts to remove spatial indexes on
nullable fields on MySQL.

MySQL doesn't support spatial indexes on NULL columns, so there is no
point in removing them.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:9>

Django

unread,
Jun 20, 2024, 5:47:27 AM (9 days ago) Jun 20
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
------------------------------+--------------------------------------------
Reporter: Mário Falcão | Owner: Mariusz Felisiak
Type: Bug | Status: assigned
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"adb72fa85423eba238d472a8abfbb65bbc2132d5" adb72fa8]:
{{{#!CommitTicketReference repository=""
revision="adb72fa85423eba238d472a8abfbb65bbc2132d5"
[5.1.x] Refs #35074 -- Avoided failed attempts to remove spatial indexes
on nullable fields on MySQL.

MySQL doesn't support spatial indexes on NULL columns, so there is no
point in removing them.

Backport of 20c2d625d3d5062e43918d1d7b6f623202491dd4 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:10>

Django

unread,
Jun 26, 2024, 7:33:28 AM (3 days ago) Jun 26
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
------------------------------+------------------------------------
Reporter: Mário Falcão | Owner: (none)
Type: Bug | Status: new
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 0 => 1
* owner: Mariusz Felisiak => (none)
* status: assigned => new

--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:11>

Django

unread,
Jun 26, 2024, 7:35:13 AM (3 days ago) Jun 26
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
------------------------------+--------------------------------------------
Reporter: Mário Falcão | Owner: Mariusz Felisiak
Type: Bug | Status: assigned
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0
* owner: (none) => Mariusz Felisiak
* status: new => assigned

Comment:

Jacob, there is still one related cleanup waiting for a review.
--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:12>

Django

unread,
Jun 26, 2024, 8:10:36 AM (3 days ago) Jun 26
to django-...@googlegroups.com
#35074: Altering spatial_index does not actually create/drop the index
------------------------------+--------------------------------------------
Reporter: Mário Falcão | Owner: Mariusz Felisiak
Type: Bug | Status: assigned
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------------
Comment (by Jacob Walls):

Thanks, the PR Mariusz mentions is:
https://github.com/django/django/pull/18175
--
Ticket URL: <https://code.djangoproject.com/ticket/35074#comment:13>
Reply all
Reply to author
Forward
0 new messages