Code

Opened 4 years ago

Closed 3 years ago

#14348 closed Bug (worksforme)

Paginator does not handle django.db.models.sql.datastructures.EmptyResultSet

Reported by: teh Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

I'd argue that it should be treated as 0 entries, i.e. the allow_empty_first_page is the proper place to catch this.

Attached patch fixes this.

Attachments (1)

0001-Handle-EmptyResultSet-exception-in-paginator.patch (1014 bytes) - added by teh 4 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 4 years ago by gabrielhurley

  • Has patch set
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

I'm curious how you got EmptyResultSet into Paginator to begin with... I thought EmptyResultSet was pretty much only used in the Django internals.

That aside, I wonder if adding a __len__ method on EmptyResultSet might be a better option than catching another exception. Treat the problem, not the symptom, right?

Also, you'll need a unit test for the patch, which would be a good way to demonstrate how EmptyResultSet gets into Paginator...

comment:2 Changed 4 years ago by Alex

  • Component changed from Core framework to Database layer (models, ORM)

EmptyResultSet should never escape the ORM internals, if it is *thats* the bug. And that's what we need a test/patch for.

comment:3 Changed 3 years ago by oberrocker

Just a hint (not a test, I'm afraid):

The problem occurred here when I filtered a queryset with __in using an empty list, e.g.

items = Location.objects.filter(zip__in=[])

The resulting queryset is empty, looking ok otherwise, but feeding it into Paginator causes an EmptyResultSet exception.

Using an empty queryset that was returned by a simple filter works as expected, e.g.

items = Location.objects.filter(name="SOIHFODIHFO")

Hope this helps.

Markus

comment:4 Changed 3 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:5 Changed 3 years ago by claudep

  • Easy pickings unset
  • Resolution set to worksforme
  • Status changed from new to closed
  • UI/UX unset

I tried with a __in=[] filter, but wasn't able to reproduce it. Until you provide us with a real failing test case, I'm closing it. Don't hesitate to reopen if you have some more concrete use case.

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.