fix(api): filter by every GIAS phase, not just the grouped ones #163

Merged
tudor merged 1 commits from fix/phase-filter-exact-match into main 2026-10-01 14:07:57 +00:00
Owner

What

Choosing Nursery, 16 plus, Middle deemed primary or Middle deemed secondary in the search page's phase filter returned the whole unfiltered result set — mostly primary schools.

Why

/api/schools looked the phase up in PHASE_GROUPS, which only has primary, secondary and all-through. For any other value the lookup returned None and the filter was skipped entirely. The dropdown lists every GIAS phase (and since #162 always does), so four of its seven options did nothing.

Fix

  • primary / secondary / all-through keep their grouping (primary takes in middle deemed primary and all-through; secondary takes in middle deemed secondary, 16 plus and all-through).
  • Any other phase is an exact, case-insensitive match.
  • An unknown phase returns no schools instead of all of them.

Tests

  • New backend/tests/test_phase_filter.py: all seven phases plus an unknown value. 5 of 6 failed before the fix (reproducing the bug); all pass after. Full backend suite: 237 passed.
  • New E2E journey: a phase outside primary/secondary filters to that phase, not to everything (nursery, 16 plus via the API). Runs on the post-merge staging gate.

Not changed

The dropdown still shows the seven raw GIAS phase names. A shorter, parent-facing list is a separate product decision.

🤖 Generated with Claude Code

## What Choosing **Nursery**, **16 plus**, **Middle deemed primary** or **Middle deemed secondary** in the search page's phase filter returned the whole unfiltered result set — mostly primary schools. ## Why `/api/schools` looked the phase up in `PHASE_GROUPS`, which only has `primary`, `secondary` and `all-through`. For any other value the lookup returned `None` and the filter was skipped entirely. The dropdown lists every GIAS phase (and since #162 always does), so four of its seven options did nothing. ## Fix - `primary` / `secondary` / `all-through` keep their grouping (primary takes in middle deemed primary and all-through; secondary takes in middle deemed secondary, 16 plus and all-through). - Any other phase is an exact, case-insensitive match. - An unknown phase returns no schools instead of all of them. ## Tests - New `backend/tests/test_phase_filter.py`: all seven phases plus an unknown value. 5 of 6 failed before the fix (reproducing the bug); all pass after. Full backend suite: 237 passed. - New E2E journey: *a phase outside primary/secondary filters to that phase, not to everything* (`nursery`, `16 plus` via the API). Runs on the post-merge staging gate. ## Not changed The dropdown still shows the seven raw GIAS phase names. A shorter, parent-facing list is a separate product decision. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tudor added 1 commit 2026-10-01 13:45:24 +00:00
fix(api): filter by every GIAS phase, not just the grouped ones
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m13s
PR Checks / Backend Smoke (pull_request) Successful in 9s
PR Checks / Build Backend (no push) (pull_request) Successful in 20s
PR Checks / Build Frontend (no push) (pull_request) Successful in 1m20s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 11s
PR Checks / AI Code Review (Claude) (pull_request) Successful in 16s
bd7c8593d9
/api/schools only recognised primary, secondary and all-through. Any
other phase the search page offers (nursery, 16 plus, middle deemed
primary/secondary) fell through to no filter, so "Nursery" returned the
whole result set, mostly primaries. Ungrouped phases now match exactly,
and an unknown phase returns nothing rather than everything.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

🤖 AI Code Review (Claude Code)

The /api/schools phase filter now matches any GIAS phase name exactly when it isn't a grouped phase (primary/secondary). It previously fell through to no filter, so 'Nursery' returned the whole result set. It also handles null phases with fillna and adds backend unit tests and an e2e test. The change is small and correct, and I found no issues.

✅ No issues found.

## 🤖 AI Code Review (Claude Code) The /api/schools phase filter now matches any GIAS phase name exactly when it isn't a grouped phase (primary/secondary). It previously fell through to no filter, so 'Nursery' returned the whole result set. It also handles null phases with fillna and adds backend unit tests and an e2e test. The change is small and correct, and I found no issues. ✅ No issues found.
tudor merged commit 2002529137 into main 2026-10-01 14:07:57 +00:00
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: tudor/school_compare#163