bug: GET /merges?mode=all returns 500 (KeyError: 'all' in merge_request_table.html)

Open Beginner friendly
#14,780 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@iykyk-vedant is already working on this.

Since Nov 29, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend, web-dev

Research direction

Read openlibrary/templates/merge_request_table/merge_request_table.html and the /merges GET handler in openlibrary/plugins/upstream/edits.py; the issue identifies the failing total[mode] lookup and the total_found counts. Check the CommunityEditsQueue.MODES values in openlibrary/core/edits.py, then reproduce /merges?mode=all as a librarian. Done when that request renders successfully and the existing open and closed modes still work.

Written by the indexing model from the issue text.

Description

Lead: @mekarpeles Module: Merging Needs: Response
Problem

GET /merges?mode=all returns HTTP 500 with KeyError: 'all'.

all is an accepted value: the /merges GET handler validates mode against CommunityEditsQueue.MODES, which includes all (openlibrary/core/edits.py), so the request passes validation and reaches the template.

Root cause

openlibrary/templates/merge_request_table/merge_request_table.html computes pagination as:

$:macros.OlPagination(page, ceil(total[mode] / 25))

but total (built by the GET handler as total_found, openlibrary/plugins/upstream/edits.py) only ever has open and closed keys — never all. When mode == "all", total["all"] raises KeyError: 'all'. The docstring on the template confirms the contract: total : dict : {"open": int, "closed": int}.

Reproduce
  1. Log in as a librarian.
  2. Visit /merges?mode=all.
  3. → 500 (KeyError: 'all' at merge_request_table.html, total[mode]).

/merges (default mode=open) and /merges?mode=closed both work.

Suggested fix (not in scope of the PR that found this)

Either derive an all total (e.g. open + closed, or a dedicated count) in the GET handler's total_found, or have the template fall back when mode isn't a key (e.g. total.get(mode, total['open'] + total['closed'])).


Found during live e2e testing of #14774 / PR #14777 (edition merge queue). Pre-existing on master, unrelated to that PR's diff — filed separately so it isn't fixed there.

Dominant language
Python
Stars
7k
Forks
2.1k
Avg merge
22h 25m
Merged PRs (30d)
384

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from internetarchive/openlibrary

All issues in internetarchive/openlibrary

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.