Opened 13 years ago

Closed 11 years ago

#16898 closed Bug (worksforme)

Throwing an exception out of a custom field (or any QuerySet._results_iter callable) results in a bad _results_cache

Reported by: Jeremy Dunck 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

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.

Change History (2)

comment:1 by Luke Plant, 13 years ago

Triage Stage: UnreviewedAccepted

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

comment:2 by anonymous, 11 years ago

Resolution: worksforme
Status: newclosed

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

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