Opened 14 years ago

Closed 10 years ago

#16092 closed Bug (wontfix)

QuerySet F() fields should be able to reference .extra() select keys

Reported by: Joshua "jag" Ginsberg <jag@…> Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

from django.db import models
from datetime import datetime

class TestModel(models.Model):
    word = models.CharField(max_length=50)
    timezone_name = models.CharField(max_length=200)
    cutoff = models.DateTimeField()

    class Meta:
        db_table = 'test_model'

obj1 = TestModel.objects.create(word='Foo', timezone_name='America/New_York', cutoff=datetime(2012,1,1,0,0,0))
obj2 = TestModel.objects.create(word='Bar', timezone_name='America/Los_Angeles', cutoff=datetime(2000,1,1,0,0,0))

qs = TestModel.objects.extra(select={'now_in_local_tz': "convert_tz(now(), 'GMT', test_model.timezone_name)"})
qs = qs.filter(cutoff__lte=models.F('now_in_local_tz'))
# FieldError: Cannot resolve keyword 'now_in_local_tz' into field. Choices are: cutoff, id, timezone_name, word

Disclaimer: I wrote the above code without testing it based on a far more complex real-world example - any typos ought not invalidate the bug.

Attachments (1)

16092-testcase.patch (1.8 KB ) - added by Aymeric Augustin 13 years ago.

Download all attachments as: .zip

Change History (4)

by Aymeric Augustin, 13 years ago

Attachment: 16092-testcase.patch added

comment:1 by Aymeric Augustin, 13 years ago

Triage Stage: UnreviewedAccepted

Here is a formal test case based on the example in the original report.

Last edited 13 years ago by Aymeric Augustin (previous) (diff)

comment:2 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:3 by Tim Graham, 10 years ago

Resolution: wontfix
Status: newclosed

I think the new expressions API in Django 1.8 mostly obsoletes this. The plan is to deprecate .extra() when all of its functionality can be achieved in other ways.

Note: See TracTickets for help on using tickets.
Back to Top