Opened 7 weeks ago

Closed 7 weeks ago

#28683 closed Bug (duplicate)

GIS Length function generates incorrect queries when evaluated multiple times

Reported by: Kordian Kowalski Owned by: nobody
Component: GIS Version: 1.11
Severity: Normal Keywords: gis geometry
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Kordian Kowalski)

In my use case, I am creating a Prefetch object that includes an annotation with the GIS Length function as its base queryset.
The prefetch object is then being reused in multiple requests.
Only the first request succeeds, all subsequent requests fail with following error messages:
django.db.utils.ProgrammingError: function st_length(geography, boolean, boolean) does not exist
django.db.utils.ProgrammingError: function st_length(geography, boolean, boolean, boolean) does not exist
django.db.utils.ProgrammingError: function st_length(geography, boolean, boolean, boolean, boolean) does not exist
As you can see, there is an additional boolean value being passed in each request.
I have narrowed down the issue to the following line (django/contrib/gis/db/models/functions.py:347) :

def as_postgresql(self, compiler, connection):
    (...)
    self.source_expressions.append(Value(self.spheroid))

The additional boolean seems to be appended to params list every time the prefetch object is compiled.
Also it seems that the problem may be affecting only postgres backends.

Steps to reproduce:

  • create a model with a django.contrib.gis.db.models.GeometryField (called geometry for this example)
  • create a queryset with Length annotation: qs = MyModel.objects.annotate(my_length=Length('geometry'))
  • run qs.all() multiple times, all subsequent requests after the first one will fail with the aforementioned message.

Change History (2)

comment:1 Changed 7 weeks ago by Kordian Kowalski

Description: modified (diff)

comment:2 Changed 7 weeks ago by Tim Graham

Resolution: duplicate
Status: newclosed
Summary: Problems with the GIS Length annotation function (django.contrib.gis.db.models.functions.Length)GIS Length function generates incorrect queries when evaluated multiple times

Duplicate of #28353 which is fixed in Django 2.0.

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