[Django] #16898: Throwing an exception out of a custom field (or any QuerySet._results_iter callable) results in a bad _results_cache

4 views
Skip to first unread message

Django

unread,
Sep 21, 2011, 2:05:37 AM9/21/11
to django-...@googlegroups.com
#16898: Throwing an exception out of a custom field (or any QuerySet._results_iter
callable) results in a bad _results_cache
-------------------------------------+-------------------------------------
Reporter: jdunck | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Database
Version: 1.3 | layer (models, ORM)
Keywords: | Severity: Normal
Has patch: 0 | Triage Stage:
Needs tests: 0 | Unreviewed
Easy pickings: 0 | Needs documentation: 0
| Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Using a custom field which breaks:
{{{
class BrokenField(DateTimeField):
__metaclass__ = SubfieldBase

def to_python(self, value):
raise TypeError("Nope.")
}}}

Assume some rows exist.

If you then create AModel using that field:

{{{
class AModel(Model):
f = BrokenField(null=True)
}}}

And you then try to query on it:
{{{
>>> qs = AModel.objects.all()
>>> qs
[]

>>> qs._result_cache is None
True
}}}
You get an empty (or truncated) results list.

I think the underlying exception should instead be raised. If it only
breaks sometimes, the results will be shorter, a very hard-to-find bug.

--
Ticket URL: <https://code.djangoproject.com/ticket/16898>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 1, 2011, 6:19:38 AM10/1/11
to django-...@googlegroups.com
#16898: Throwing an exception out of a custom field (or any QuerySet._results_iter
callable) results in a bad _results_cache
-------------------------------------+-------------------------------------
Reporter: jdunck | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.3
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by lukeplant):

* stage: Unreviewed => Accepted


Comment:

There may be some reason why this is hard to do, but I have accepted the
bug in principle.

--
Ticket URL: <https://code.djangoproject.com/ticket/16898#comment:1>

Django

unread,
Sep 6, 2013, 2:41:59 PM9/6/13
to django-...@googlegroups.com
#16898: Throwing an exception out of a custom field (or any QuerySet._results_iter
callable) results in a bad _results_cache
-------------------------------------+-------------------------------------
Reporter: jdunck | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.3
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by anonymous):

* status: new => closed
* resolution: => worksforme


Comment:

This seems to be fixed in 1.5 since the _result_cache setup changed

--
Ticket URL: <https://code.djangoproject.com/ticket/16898#comment:2>

Reply all
Reply to author
Forward
0 new messages