Opened 8 years ago

Closed 6 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


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

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 Changed 7 years ago by Luke Plant

Triage Stage: UnreviewedAccepted

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

comment:2 Changed 6 years ago by anonymous

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