blog_index view has inverted last_page logic using has_previous() instead of not has_next()
Description
In src/blog/views.py, the blog_index() view sets last_page in the context using page.has_previous(), which is semantically inverted. has_previous() returns True when there are pages before the current one — which is true for every page except the first. This means last_page is False only on the first page and True on all others, which is the opposite of what the variable name suggests.
Location
File: src/blog/views.py
Function: blog_index()
Branch: develop
Current Code
context = {
"next_page_number": page_number + 1,
"posts": posts,
"PREVIEW_SIZE": PREVIEW_SIZE,
"last_page": page.has_previous(), # WRONG: True when NOT on first page
"total_pages": paginator.num_pages,
"page_url": "/memories/",
"blog_categories": Category.objects.all(),
}
Problem
page.has_previous()returnsTruewhen there are pages before the current page — i.e., for every page except page 1.- The variable
last_pageis presumably used in the template to detect whether the user has reached the final page (to hide a "load more" button or show an end-of-feed indicator). - With the current logic,
last_pageis alwaysTrueexcept on page 1, causing the template to think the feed has ended on the second page.
Suggested Fix
"last_page": not page.has_next(),
This correctly sets last_page to True only when there are no more pages to load.
Severity
Medium — Causes incorrect pagination UI behavior: the "load more" button or infinite scroll may stop working prematurely after the first page.
Hey! I may be able to help with this bug.
I build custom fixes for Python projects and automation systems.
If you'd like help resolving this issue quickly feel free to reach out.
Happy to take a look 👍
@FocusMode-coder hey!
feel free to take a look.
Looks legitimate, but I'm not sure I've understood the problem. It says that this causes incorrect pagination and I haven't been able to verify any errors on pagination as is. If this has_next method exists, this should make the current code cleaner and easier to read.
Reading this again, and this is a case of AI hallucination and slop, that caused two merge requests and multiple comments. This last_page parameter is not even used anywhere, the solution should be remove the last_page variable from the blog index context and ensure the tests still work
You're right, and the grep backs it up: last_page was set in blog_index() and read nowhere — no template, no other view, no test. So the "incorrect pagination" symptom this issue opens with never existed, which is exactly what you couldn't reproduce.
I'd already opened #978 fixing the flag's value before reading this thread, which would have been a third PR chasing the same non-bug. It's now reworked to do what you asked: remove last_page from the context, with one test asserting the key is absent so a flag with no reader doesn't come back. Net diff against develop is one deleted line plus that test.
Generated by Claude Code