Module 8 of 9 · Lesson 24 of 26
Repair a repeated-page bug with a regression
Work through repair a repeated-page bug with a regression using a runnable reference, a focused regression check and a local extension.
Read in any order. All lessons stay open, including after an unanswered or incorrect check.
The test retains the broken result as a negative control: it proves the dataset actually exposes the defect. A test that happens to pass without exercising the boundary cannot protect the repair. Compare sets of UUIDs across pages and require the expected remaining count, rather than asserting only status 200 or nonempty JSON. Lesson 9 adds equal timestamps to protect the tie-breaker as well. Keep owner scope, sort columns, cursor encoding and filter direction consistent. Write down the invariant before editing: every permitted record should appear once in this stable test dataset. Page views or a clean browser appearance alone do not establish that invariant.
Run lesson24. Inspect broken and repaired queries in the test. The broken second page must contain the first page's last UUID; the repaired page must have no overlap and exactly one remaining row. This makes the defect and fix visible in the same isolated fixture.
def test_lesson24(db):
factory, ids = db
with factory.begin() as session:
session.add_all(
[
Rental(equipment_id=ids["item"], owner_id=ids["owner"], quantity=1)
for _ in range(3)
]
)
with factory() as session:
first = session.scalars(page_statement(ids["owner"], limit=2)).all()
cursor = cursor_for(first[-1])
broken = session.scalars(
page_statement(ids["owner"], cursor, limit=2, inclusive=True)
).all()
repaired = session.scalars(page_statement(ids["owner"], cursor, limit=2)).all()
assert first[-1].id in {
row.id for row in broken
} # the negative control reproduces the defect
assert not {row.id for row in first} & {row.id for row in repaired}
assert len(repaired) == 1
python run_checks.py -k lesson24
Expected result The selected lesson test passes against a new temporary PostgreSQL database; the container is removed afterward.
Keep for reference
Equipment Rental lab and lesson checks
ZIP containing Python source, real Alembic migrations, 26 lesson checks, a dependency lock and text instructions. Extract it before following the local exercise.
Practise locally
Add a regression for identical timestamps and a separate malformed-cursor response test. Temporarily change the production helper to inclusive comparison in your copy and confirm the repaired assertion fails. Restore it and rerun. Save the failing and passing reports with one sentence describing the strict boundary correction.
The lesson check verifies the reference behavior. Add your own assertions for your change. Local practice is not uploaded or scored by this learning release.
Pause and reflect
What failure does this lesson prevent, and which assertion in lesson24 would expose it?
Use a concrete input, expected result and limitation from your local work. Saving a reflection does not certify the project.
Optional knowledge check
What makes a pagination regression meaningful?
Use randomly spaced timestamps and check only the first page length.
Try another answer. A deterministic boundary fixture and cross-page UUID comparison expose this defect.
It reproduces overlap with the broken boundary and rejects overlap after repair.
Correct. The negative control proves the fixture exposes the actual defect.
It checks only that both page requests return 200.
Try another answer. Successful HTTP statuses do not prove rows are unique or complete across pages.
This practice does not assess your project or award a certificate.
Your reading progress
Progress is saved in this browser when storage is available.