[Django] #36694: GistIndex with condition ignores condition

4 views
Skip to first unread message

Django

unread,
Oct 28, 2025, 6:49:53 PM10/28/25
to django-...@googlegroups.com
#36694: GistIndex with condition ignores condition
----------------------------+--------------------------------------
Reporter: Lucianod28 | Type: Bug
Status: new | Component: Migrations
Version: 5.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
----------------------------+--------------------------------------
I have this model:

{{{
class Foo(CustomModel):
location = geomodels.PointField(geography=True, spatial_index=False)
is_current = models.BooleanField()

class Meta:
indexes = [
GistIndex(fields=["location"], condition=Q(is_current=True),
name="current_foo"),
]
}}}
When I create the migration, the sql for my current_foo index is:

{{{
CREATE INDEX "current_foo" ON "webatds_foo" USING GIST ("location");
}}}
This ignores my condition, I expect it to be:
{{{
CREATE INDEX "current_foo" ON "webatds_foo" USING GIST ("location") where
is_current=true;
}}}
I'm using django 5.2.7, psycopg 3.2.12, and PostGIS 17.3.5.
--
Ticket URL: <https://code.djangoproject.com/ticket/36694>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 28, 2025, 6:57:25 PM10/28/25
to django-...@googlegroups.com
#36694: GistIndex with condition ignores condition
----------------------------+--------------------------------------
Reporter: Lucianod28 | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 5.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
----------------------------+--------------------------------------
Description changed by Lucianod28:

Old description:

> I have this model:
>
> {{{
> class Foo(CustomModel):
> location = geomodels.PointField(geography=True, spatial_index=False)
> is_current = models.BooleanField()
>
> class Meta:
> indexes = [
> GistIndex(fields=["location"], condition=Q(is_current=True),
> name="current_foo"),
> ]
> }}}
> When I create the migration, the sql for my current_foo index is:
>
> {{{
> CREATE INDEX "current_foo" ON "webatds_foo" USING GIST ("location");
> }}}
> This ignores my condition, I expect it to be:
> {{{
> CREATE INDEX "current_foo" ON "webatds_foo" USING GIST ("location") where
> is_current=true;
> }}}
> I'm using django 5.2.7, psycopg 3.2.12, and PostGIS 17.3.5.

New description:

I have this model:

{{{
class Foo(models.Model):
location = geomodels.PointField(geography=True, spatial_index=False)
is_current = models.BooleanField()

class Meta:
indexes = [
GistIndex(fields=["location"], condition=Q(is_current=True),
name="current_foo"),
]
}}}
When I create the migration, the sql for my current_foo index is:

{{{
CREATE INDEX "current_foo" ON "webatds_foo" USING GIST ("location");
}}}
This ignores my condition, I expect it to be:
{{{
CREATE INDEX "current_foo" ON "webatds_foo" USING GIST ("location") where
is_current=true;
}}}
I'm using django 5.2.7, psycopg 3.2.12, and PostGIS 17.3.5.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36694#comment:1>
Reply all
Reply to author
Forward
0 new messages