Hah. That was a pretty long message relative to how quickly I found
the answer myself :-p
Sorry for the noise.

For posterity, extra(where=...) is indeed the solution. I overlooked
the obvious:
the class I was trying to fix is itself a subclass of QuerySet.  So
given this line:

    clone.query.extra_where += ('db_newsitem.id =
db_attribute.news_item_id',)

the replacement is now:

    clone = clone.extra(where=('db_newsitem.id =
db_attribute.news_item_id',))

Seems to work fine.

On Sep 1, 11:41 pm, Paul Winkler <sli...@gmail.com> wrote:
> Hi folks,
>
> I'm working on a codebase (a fork ofhttp://code.google.com/p/ebcode/)
> that is supposed to be run against Django 1.1. It has several lines
> like this:
>
>     clone.query.extra_where += ('db_newsitem.id =
> db_attribute.news_item_id',)
>
> That line raises a traceback like this:
>
> Traceback (most recent call last):
>   File "./everyblock/everyblock/cities/boston/building_permits/
> retrieval.py", line 90, in <module>
>     PermitScraper().update()
>   File "/home/pw/builds/openblock/builds/20100824/ebdata/ebdata/
> retrieval/scrapers/newsitem_list_detail.py", line 208, in update
>     super(NewsItemListDetailScraper, self).update()
>   File "/home/pw/builds/openblock/builds/20100824/ebdata/ebdata/
> retrieval/scrapers/list_detail.py", line 112, in update
>     self.update_from_string(page)
>   File "/home/pw/builds/openblock/builds/20100824/ebdata/ebdata/
> retrieval/scrapers/list_detail.py", line 140, in update_from_string
>     old_record = self.existing_record(list_record)
>   File "./everyblock/everyblock/cities/boston/building_permits/
> retrieval.py", line 65, in existing_record
>     qs = qs.by_attribute(self.schema_fields['raw_address'],
> record['address'])
>   File "/home/pw/builds/openblock/builds/20100824/ebpub/ebpub/db/
> models.py", line 317, in by_attribute
>     clone = self.prepare_attribute_qs()
>   File "/home/pw/builds/openblock/builds/20100824/ebpub/ebpub/db/
> models.py", line 300, in prepare_attribute_qs
>     clone.query.extra_where += ('db_newsitem.id =
> db_attribute.news_item_id',)
> AttributeError: 'GeoQuery' object has no attribute 'extra_where'
>
> For more context, the relevant models.py code is 
> athttp://github.com/openplans/openblock/blob/master/ebpub/ebpub/db/mode...
> and `clone.query` is an instance of
> django.contrib.gis.db.models.sql.query.GeoQuery, which inherits from
> the usual BaseQuery.
>
> Now, I've found by googling and downloading old releases that
> django.db.models.sql.query.BaseQuery had an extra_where attribute as
> of Django 1.0, but it's gone in Django 1.1.
> And from looking at recent and old versions of the docs, I don't think
> that extra_where was ever really part of the API; you're probably not
> supposed to twiddle it directly.
>
> I haven't yet found a documented way to solve 
> this.http://docs.djangoproject.com/en/dev/ref/models/querysets/talks about
> the .extra(where=...) method,
> but that's part of the manager API and the QuerySet API, not the Query
> API.
>
> The one thing I've found, by poking around in the django source, is to
> call clone.query.where.add(ExtraWhere(...)) but it's not clear to me
> whether that's really part of the API either. Is there a better /
> "correct" way?
>
> Thanks,

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to