[Django] #25605: GeoDjango DB functions doesn't really work with expressions

59 views
Skip to first unread message

Django

unread,
Oct 25, 2015, 10:12:29 AM10/25/15
to django-...@googlegroups.com
#25605: GeoDjango DB functions doesn't really work with expressions
----------------------------+--------------------
Reporter: sir-sigurd | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
geotest/models.py:
{{{
class Test(models.Model):
point1 = models.PointField()
point2 = models.PointField()
}}}

python manage.py shell

{{{
In [1]: %paste
from django.contrib.gis.db.models.functions import Distance
from django.contrib.gis.geos import Point

from geotest.models import Test

point1 = Point(0, 0, srid=4326)
point2 = Point(0, 1, srid=4326)
Test.objects.create(point1=point1, point2=point2)

## -- End pasted text --
Out[1]: <Test: Test object>

In [2]: print Test.objects.annotate(dist=Distance('point1',
point2)).last().dist
111195.079735 m

In [3]: print Test.objects.annotate(dist=Distance(point1,
'point2')).last().dist
GEOS_ERROR: ParseException: Unknown type: 'POINT2'

---------------------------------------------------------------------------
ValueError Traceback (most recent call
last)
<ipython-input-3-aa91ca51a4df> in <module>()
----> 1 print Test.objects.annotate(dist=Distance(point1,
'point2')).last().dist

/home/sergey/dev/django/django/contrib/gis/db/models/functions.pyc in
__init__(self, expr1, expr2, spheroid, **extra)
239 self.spheroid = spheroid
240 expressions += (self._handle_param(spheroid,
'spheroid', bool),)
--> 241 super(Distance, self).__init__(*expressions, **extra)
242
243 def as_postgresql(self, compiler, connection):

/home/sergey/dev/django/django/contrib/gis/db/models/functions.pyc in
__init__(self, expression, geom, *expressions, **extra)
97 geom = GEOSGeometry(geom)
98 except Exception:
---> 99 raise ValueError("This function requires a
geometric parameter.")
100 if not geom.srid:
101 raise ValueError("Please provide a geometry attribute
with a defined SRID.")

ValueError: This function requires a geometric parameter.

In [4]: print Test.objects.annotate(dist=Distance('point1',
'point2')).last().dist
GEOS_ERROR: ParseException: Unknown type: 'POINT2'

---------------------------------------------------------------------------
ValueError Traceback (most recent call
last)
<ipython-input-4-177990c7d19a> in <module>()
----> 1 print Test.objects.annotate(dist=Distance('point1',
'point2')).last().dist

/home/sergey/dev/django/django/contrib/gis/db/models/functions.pyc in
__init__(self, expr1, expr2, spheroid, **extra)
239 self.spheroid = spheroid
240 expressions += (self._handle_param(spheroid,
'spheroid', bool),)
--> 241 super(Distance, self).__init__(*expressions, **extra)
242
243 def as_postgresql(self, compiler, connection):

/home/sergey/dev/django/django/contrib/gis/db/models/functions.pyc in
__init__(self, expression, geom, *expressions, **extra)
97 geom = GEOSGeometry(geom)
98 except Exception:
---> 99 raise ValueError("This function requires a
geometric parameter.")
100 if not geom.srid:
101 raise ValueError("Please provide a geometry attribute
with a defined SRID.")

ValueError: This function requires a geometric parameter.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25605>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 25, 2015, 10:14:04 AM10/25/15
to django-...@googlegroups.com
#25605: GeoDjango DB functions doesn't really work with expressions
----------------------------+--------------------------------------

Reporter: sir-sigurd | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by sir-sigurd):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

PR -- https://github.com/django/django/pull/5477

--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:1>

Django

unread,
Oct 25, 2015, 5:28:30 PM10/25/15
to django-...@googlegroups.com
#25605: GeoDjango DB functions doesn't really work with expressions
----------------------------+------------------------------------

Reporter: sir-sigurd | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by claudep):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:2>

Django

unread,
Oct 27, 2015, 8:11:48 AM10/27/15
to django-...@googlegroups.com
#25605: GeoDjango DB functions doesn't really work with expressions
----------------------------+------------------------------------

Reporter: sir-sigurd | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:3>

Django

unread,
Oct 28, 2015, 9:38:36 AM10/28/15
to django-...@googlegroups.com
#25605: GeoDjango DB functions doesn't really work with expressions
----------------------------+--------------------------------------
Reporter: sir-sigurd | Owner: sir-sigurd
Type: Bug | Status: assigned
Component: GIS | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by sir-sigurd):

* owner: nobody => sir-sigurd
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:4>

Django

unread,
Nov 4, 2015, 2:09:18 PM11/4/15
to django-...@googlegroups.com
#25605: GIS functions don't work with left-hand-side expressions

----------------------------+--------------------------------------
Reporter: sir-sigurd | Owner: sir-sigurd
Type: Bug | Status: assigned
Component: GIS | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:5>

Django

unread,
Dec 9, 2016, 5:58:53 AM12/9/16
to django-...@googlegroups.com
#25605: GIS functions don't work with left-hand-side expressions
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: Sergey
| Fedoseev
Type: Bug | Status: assigned
Component: GIS | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sergey Fedoseev):

* needs_better_patch: 1 => 0


Comment:

[https://github.com/django/django/pull/7670 new PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:6>

Django

unread,
Mar 14, 2017, 3:09:41 AM3/14/17
to django-...@googlegroups.com
#25605: GIS functions don't work with left-hand-side expressions
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: Sergey
| Fedoseev
Type: Bug | Status: assigned
Component: GIS | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Sergey Fedoseev):

I closed #27529 as a duplicate.

--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:7>

Django

unread,
Mar 15, 2017, 12:10:41 PM3/15/17
to django-...@googlegroups.com
#25605: GIS functions don't work with left-hand-side expressions
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: Sergey
| Fedoseev
Type: Bug | Status: assigned
Component: GIS | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25605#comment:8>

Django

unread,
Apr 1, 2017, 9:47:57 AM4/1/17
to django-...@googlegroups.com
#25605: GIS functions don't work with left-hand-side expressions
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: Sergey
| Fedoseev
Type: Bug | Status: closed
Component: GIS | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"bde86ce9ae17ee52aa5be9b74b64422f5219530d" bde86ce9]:
{{{
#!CommitTicketReference repository=""
revision="bde86ce9ae17ee52aa5be9b74b64422f5219530d"
Fixed #25605 -- Made GIS DB functions accept geometric expressions, not
only values, in all positions.
}}}

Reply all
Reply to author
Forward
0 new messages