Opened 14 hours ago
Last modified 3 hours ago
#36694 assigned Bug
PostGIS backend silently ignores most Index options when targeting a single GeometryField (expressions, condition, include, opclasses)
| Reported by: | Luciano de la Iglesia | Owned by: | Clifford Gama |
|---|---|---|---|
| Component: | GIS | Version: | 5.2 |
| Severity: | Normal | Keywords: | postgis index condition include |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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.
Change History (5)
comment:1 by , 14 hours ago
| Description: | modified (diff) |
|---|
comment:2 by , 11 hours ago
| Component: | Migrations → GIS |
|---|---|
| Keywords: | postgis index condition include added |
| Summary: | GistIndex with condition ignores condition → PostGIS backend silently ignores most Index options (expressions, condition, include, opclasses) |
| Triage Stage: | Unreviewed → Accepted |
Version 0, edited 11 hours ago by (next)
comment:3 by , 11 hours ago
| Summary: | PostGIS backend silently ignores most Index options (expressions, condition, include, opclasses) → PostGIS backend silently ignores most Index options when targeting a single GeometryField (expressions, condition, include, opclasses) |
|---|
comment:4 by , 11 hours ago
A workaround in the meantime could be to use expressions=[F("location")] instead of fields=["location"]. You might have to explicitly specify the proper opclasses though, that would be point_ops in your case.
comment:5 by , 3 hours ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
Note:
See TracTickets
for help on using tickets.
Confirmed this is a bug in in
django.contrib.gis.db.backends.postgist(I inferred you were using PostGIS given you usecontrib.postgres.ArrayField).The
SchemaEditor._create_index_sqlmethod delegates to._create_spatial_index_sqlto provide some defaults (e.g.opclasses) but fails to pass alongkwargssuch ascondition,include,expressions, etc. It seems broken in multiple ways.