﻿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
27529	Geographic database functions with two parameters should accept expressions in one or the other arguments	Antoine Auberger	nobody	"== Context
With the release of Django 1.9 database functions were introduced to simplify measurements, operations, lookups, etc. within the queryset.

Some of the functions introduced take two arguments : `Difference`, `Distance`, `Intersection`, `SymDifference` and `Union`.
The doc [#point1 (1)] states these functions ""Accepts two geographic fields or expressions and returns the distance between them"".

== Problem
As they all inherit from `GeoFuncWithGeoParam` [#point2 (2)], they actually expect `expr1` to be an expression (column or value), and `expr2` to be a `GEOSGeometry` object, despite stated otherwise.

If an expression is passed as `expr2`, this error is raised :
{{{
In [0]: MyClass.objects.annotate(distance=Distance('field1', 'field2'))

[...]

ValueError: Please provide a geometry attribute with a defined SRID.
}}}

== Solutions
1. Edit the doc to mention these limitations
2. (much better) Fix the code to accept expressions in `expr2` as documented (and `GEOSGeometry` objects as expr1). Most of the backends support geographic measurements and operations between two fields, so there is not much to change.

Happy to work on a patch if the bug is validated.

[=#point1 (1)] https://docs.djangoproject.com/en/dev/ref/contrib/gis/functions/#distance
[=#point2 (2)] https://github.com/django/django/blob/1.9/django/contrib/gis/db/models/functions.py#L91"	Bug	closed	GIS	dev	Normal	duplicate	gis geographic queryset		Accepted	0	0	0	0	0	0
