Opened 5 years ago

Closed 5 years ago

#12361 closed (duplicate)

GIS DB query generates invalid SQL on two joins with the same table

Reported by: wardi Owned by: nobody
Component: GIS Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

from django.contrib.gis.db import models
from django.contrib.gis.geos import Point

class TestModel(models.Model):
    objects = models.GeoManager()

    point = models.PointField()

class RefModel(models.Model):
    objects = models.GeoManager()

    test1 = models.ForeignKey(TestModel, related_name="test1s")
    test2 = models.ForeignKey(TestModel, related_name="test2s")

bool(RefModel.objects.filter(test1__point=Point(1,0), test2__point=Point(2,0)))

causes a psycopg2.ProgrammingError: Missing FROM-clause entry for table "T3"

If point is a CharField or other non-GIS field there is no error. There is also no error if I don't use GeoManager instances (which is itself incorrect in this case).

Change History (1)

comment:1 Changed 5 years ago by jbronn

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #11741. A patch will be available after multi-db lands.

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