Opened 7 years ago
Last modified 7 years ago
#28683 closed Bug
Problems with the GIS Length annotation function (django.contrib.gis.db.models.functions.Length) — at Initial Version
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
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.