On Jun 3, 7:11 pm, Don Spaulding <donspauldin...@gmail.com> wrote:
> On Jun 3, 5:59 pm, Don Spaulding <donspauldin...@gmail.com> wrote:
>
>
>
> > On Jun 3, 5:22 pm, Don Spaulding <donspauldin...@gmail.com> wrote:
>
> > > On Jun 3, 3:05 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
>
> > > > On Wed, Jun 3, 2009 at 3:03 PM, Don Spaulding 
> > > > <donspauldin...@gmail.com>wrote:
>
> > > > > bump.
>
> > > > > Can anyone tell me if this looks like a bug in Django?
>
> > > > > On Jun 1, 6:12 pm, Don Spaulding <donspauldin...@gmail.com> wrote:
> > > > > > Hi all,
>
> > > > > > I've got a quick use case that I think should work according to the
> > > > > > docs, but it's not.  In this case, Domain objects have a reverse 
> > > > > > fkey
> > > > > > relation named "reports", and the Report model has an "updated"
> > > > > > field.  I'd like to annotate and order Domains by the max value of
> > > > > > "updated" for all related reports.  The following interactive 
> > > > > > session
> > > > > > shows the behavior pretty well.
>
> > > > > > >>> qs =
> > > > > Domain.objects.annotate(last_updated=Max('reports__updated')).order_by('last_updated')
> > > > > > >>> qs.count()
> > > > > > 1577
> > > > > > >>> print qs[0].last_updated
>
> > > > > > IndexError: list index out of range>>> qs.count()
>
> > > > > > InternalError: current transaction is aborted, commands ignored 
> > > > > > until
> > > > > > end of transaction block
>
> > > > > > >>> connection._rollback()
>
> > > > > > If I drop off the order_by call, things appear to work again.
>
> > > > > > >>> qs = 
> > > > > > >>> Domain.objects.annotate(last_updated=Max('reports__updated'))
> > > > > > >>> qs.count()
> > > > > > 1577
> > > > > > >>> print qs[0].last_updated
>
> > > > > > 2009-05-28 13:25:55.027600
>
> > > > > > What am I missing here (besides a thorough understanding of
> > > > > > aggregation)?
>
> > > > It looks like a bug in django at first glance.  Out of curiosity what
> > > > version of Django is it, since it looks a tiny bit like an old bug with
> > > > queryset chaining, but I think that was fixed even before the first 
> > > > beta.
> > > >>> django.get_version()
>
> > > u'1.1 beta 1 SVN-10916'
>
> > Hmm, after updating to u'1.1 beta 1 SVN-10921' I'm now getting a
> > psycopg2.ProgrammingError:  ORDER BY "last_updated" is ambiguous.
>
> > I've put the SQL it generates (I've only sanitized the two table
> > names) up athttp://dpaste.com/51213/
>
> And of course, therein lies my problem, I've gone and tried to
> annotate each record with a 'last_updated' calculation, and the model
> already has an actual 'last_updated' field.  The error only shows up
> when django tries to tell the SQL engine to order_by something that's
> been defined twice in the query.
>
> I'll raise a ticket on the tracker about possibly raising an exception
> instead of allowing users (stupid ones like me) to clobber their own
> namespaces.

Ticket filed at: http://code.djangoproject.com/ticket/11256
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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