#28621: Crash in QuerySet.annotate() with OuterRef -------------------------------------+------------------------------------- Reporter: Дилян Палаузов | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 1.11 (models, ORM) | Severity: Normal | Resolution: Keywords: QuerySet.extra | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Filip Kilibarda): Replying to [comment:6 Ben Davis]: > I am also getting this error. Is there a workaround? > > `AttributeError: 'ResolvedOuterRef' object has no attribute 'contains_aggregate'` > > My query looks like this: > {{{#!python > class ProgramQuerySet(models.QuerySet): > def with_remaining_volunteers_needed(self): > sessions_query = ( > Session.objects > .filter(program=OuterRef('id')) > .annotate(needed=OuterRef('volunteers_per_session') - Count('volunteer_attendances')) > .order_by('-needed') > .values('needed')[:1] > ) > > return self.annotate( > volunteers_per_session=(F('num_student_seats') * F('student_volunteer_ratio')), > needed=Subquery(sessions_query, output_field=models.IntegerField()) > ) > }}} I'm having exactly the same issue. Have you found a workaround for this? -- Ticket URL: <https://code.djangoproject.com/ticket/28621#comment:7> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/072.4e4c17d7003374622bbfebdd0b35abde%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.