Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#10807 closed (fixed)

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

Reported by: bretthoerner 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: UI/UX:

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'

Attachments (0)

Change History (6)

comment:1 Changed 5 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 5 years ago by bretthoerner

  • Owner changed from nobody to bretthoerner
  • Status changed from new to assigned

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 Changed 5 years ago by bretthoerner

  • Owner bretthoerner deleted
  • Status changed from assigned to new

Whoops, un-assigning.

comment:4 Changed 5 years ago by bretthoerner

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 Changed 5 years ago by jbronn

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:6 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.