Opened 15 years ago
Closed 14 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)
Change History (6)
by , 15 years ago
| Attachment: | 0001-Handle-EmptyResultSet-exception-in-paginator.patch added |
|---|
comment:1 by , 15 years ago
| Has patch: | set |
|---|---|
| Needs tests: | set |
| Patch needs improvement: | set |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 15 years ago
| Component: | Core framework → 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 by , 15 years ago
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 by , 14 years ago
| Severity: | → Normal |
|---|---|
| Type: | → Bug |
comment:5 by , 14 years ago
| Easy pickings: | unset |
|---|---|
| Resolution: | → worksforme |
| Status: | new → 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.
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...