#32750: ExtractMonth from OuterRef in Subquery don't work
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
Chiorufarewerin |
Type: Bug | Status: assigned
Component: Database | Version: dev
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Just example code:
{{{
DTModel.objects.create(name='1', start_datetime=datetime(2000, 1, 1))
DTModel.objects.create(name='2', start_datetime=datetime(2001, 2, 5))
DTModel.objects.create(name='3', start_datetime=datetime(2002, 1, 7))
DTModel.objects.create(name='4', start_datetime=datetime(2003, 2, 8))
subquery_qs = DTModel.objects.filter(
name__in=['3', '4'],
start_datetime__month=ExtractMonth(OuterRef('start_datetime')),
)
qs = DTModel.objects.filter(name__in=['1', '2'])
qs = qs.annotate(related_name=Subquery(subquery_qs.values('name')[:1]))
}}}
This code raises where ExtractMonth(OuterRef('start_datetime')):
{{{
'ResolvedOuterRef' object has no attribute 'output_field'
}}}
It can be works with something like:
{{{
start_datetime__month=ExtractMonth(Func(OuterRef('start_datetime'),
function='', output_field=DateTimeField())),
}}}
Or if redefine class:
{{{
class ExtractMonthCustom(ExtractMonth):
def resolve_expression(self, *args, **kwargs):
return super(Extract, self).resolve_expression(*args, **kwargs)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32750>
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/058.f1df421023ce3c7e9332103fa5422391%40djangoproject.com.