#24486 closed Bug (fixed)
UnboundLocalError in db.models.expressions
Reported by: | Michael Angeletti | Owned by: | Josh Smeaton |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.8beta2 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
After filing #24485, I stumbled into a bug that is somewhat related, in the sense of its relationship to output_field
and DurationField
support in general. An UnboundLocalError
occurs @ https://github.com/django/django/blob/ceaf31adfff3801f1092a215f73704e15a70e90c/django/db/models/expressions.py#L401.
I discovered this while running the following:
Ticket.objects.filter( active_at__lte=now, active_at__gt=now - models.F('duration') )
Using the following model:
class Ticket(models.Model): # ... other fields omitted active_at = models.DateTimeField() duration = models.DurationField()
I've categorized this as a release blocker, because it prohibits the use of DurationField
with F
.
Change History (8)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
@jarshwa I'm using sqlite3 (local dev). I don't think there is anything in the code that could result in this difference, but in the morning I will create a new app and try to replicate it in isolation. Perhaps, there is something else in my app that is having some sort of affect.
comment:3 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
Version: | master → 1.8beta2 |
@yoyoma it *is* triggered by databases where: not connection.features.has_native_duration_field
such as sqlite. I've got enough to investigate, thanks for the report.
comment:4 by , 10 years ago
Has patch: | set |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Pull request: https://github.com/django/django/pull/4328
comment:5 by , 10 years ago
@jarshwah thanks. I've just donated $25 to the Django Fellowship program as a small thanks for your help, as well as the help of @timgraham who helped me with a few tickets recently.
comment:8 by , 10 years ago
For posterity, the patch addressed the issue fully, and sqlite3 is also supported. Thanks again, @timgraham and @jarshwah.
I can see the problem in the code, but I can't replicate the error for some reason.
Is there something else in your query that helps to trigger this condition? Though I doubt it'll make a difference, which database are you using to test?