Opened 4 years ago

Closed 20 months 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: jdunck 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 Changed 4 years ago by lukeplant

  • Triage Stage changed from Unreviewed to Accepted

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

comment:2 Changed 20 months ago by anonymous

  • Resolution set to worksforme
  • Status changed from new to closed

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