Code

Opened 3 years ago

Closed 8 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.

Attachments (0)

Change History (2)

comment:1 Changed 3 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 8 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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.