﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28683	Problems with the GIS Length annotation function (django.contrib.gis.db.models.functions.Length)	Kordian Kowalski	nobody	"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`
- 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."	Bug	new	GIS	1.11	Normal		gis geometry		Unreviewed	0	0	0	0	0	0
