Opened 15 years ago

Closed 15 years ago

Last modified 12 years ago

#10807 closed (fixed)

'Constraint' object has no attribute 'relabel_aliases' when using | with GeoQueryset

Reported by: Brett Hoerner Owned by:
Component: GIS Version: 1.1-beta
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

from django.contrib.auth.models import User
from django.contrib.gis.db import models


class Place(models.Model):
    name = models.CharField(max_length=100)
    location = models.PointField()

    objects = models.GeoManager()

    def __unicode__(self):
        return self.name
from django.contrib.gis.geos import Point
from django.contrib.gis.measure import D

from djtest.models import Place

point = Point(x=0, y=0)

place1 = Place.objects.create(name='A', location=point)
place2 = Place.objects.create(name='B', location=point)

qs1 = Place.objects.filter(name='A', location__distance_lte=(point, D(mi=5)))
qs2 = Place.objects.filter(name='B', location__distance_lte=(point, D(mi=5)))
qs1 | qs2
Traceback (most recent call last):
  File "test.py", line 13, in <module>
    qs1 | qs2
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/query.py", line 163, in __or__
    combined.query.combine(other.query, sql.OR)
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/sql/query.py", line 500, in combine
    w.relabel_aliases(change_map)
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/sql/where.py", line 226, in relabel_aliases
    child[0].relabel_aliases(change_map)
AttributeError: 'Constraint' object has no attribute 'relabel_aliases'

Change History (6)

comment:1 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Brett Hoerner, 15 years ago

Owner: changed from nobody to Brett Hoerner
Status: newassigned

I used git-bisect that it broke on [9702],

Traceback (most recent call last):
  File "../djtest/test.py", line 13, in <module>
    print qs1 | qs2
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/query.py", line 255, in __or__
    combined.query.combine(other.query, sql.OR)
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/sql/query.py", line 373, in combine
    w.relabel_aliases(change_map)
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/sql/where.py", line 211, in relabel_aliases
    elt = list(child[0])
TypeError: 'Constraint' object is not iterable

[9702] were changes to catch up with [9700] on trunk, where the above test case gives the following,

Traceback (most recent call last):
  File "../djtest/test.py", line 11, in <module>
    qs1 = Place.objects.filter(name='A', location__distance_lte=(point, D(mi=5)))
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/manager.py", line 102, in filter
    return self.get_query_set().filter(*args, **kwargs)
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/query.py", line 489, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/query.py", line 507, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/sql/query.py", line 1241, in add_q
    can_reuse=used_aliases)
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/sql/query.py", line 1184, in add_filter
    connector)
  File "/a/djtest/lib/python2.6/site-packages/django/contrib/gis/db/models/sql/where.py", line 32, in add
    alias, col, field, lookup_type, value = data     
ValueError: need more than 3 values to unpack

comment:3 by Brett Hoerner, 15 years ago

Owner: Brett Hoerner removed
Status: assignednew

Whoops, un-assigning.

comment:4 by Brett Hoerner, 15 years ago

Well, it looks like the first occurrence of the relabel_aliases error (rather than Constraint is not iterable error in the above comment) is in [9888],

Traceback (most recent call last):
  File "../djtest/test.py", line 13, in <module>
    print qs1 | qs2
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/query.py", line 256, in __or__
    combined.query.combine(other.query, sql.OR)
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/sql/query.py", line 487, in combine
    w.relabel_aliases(change_map)
  File "/a/djtest/lib/python2.6/site-packages/django/db/models/sql/where.py", line 222, in relabel_aliases
    child[0].relabel_aliases(change_map)
AttributeError: 'Constraint' object has no attribute 'relabel_aliases'

comment:5 by jbronn, 15 years ago

Resolution: fixed
Status: newclosed

(In [10559]) Fixed #10807 - GeoWhereNode no longer passes Constraint objects to where they shouldn'"'"'t go.

comment:6 by Jacob, 12 years ago

milestone: 1.1

Milestone 1.1 deleted

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