oliver-zehentleitner / maity

clean-up: hub-wide: one errors.project_closed helper for the 409 built inline at 13 sites

Sign in to report

tsk-p3a14j8p1rg9 Open

From the clean-up audit tsk-hgnbapyw7hnh (finding A4-10, the project_closed part), read at 80647565. Line numbers are at that SHA; check them against current main first. Paths are under hub/src/maity_hub/.

What is wrong

Every site writes the same check and the same error by hand: if <project>.state in CLOSED_STATES: raise ApiError(409, "project_closed", f"the project is {state}"). errors.py already has builders for the common errors (forbidden, invalid, not_found), but none for this one, so the code and message are repeated 13 times.

Sites (git grep at 80647565)

  • attachments.py:347, group_chats.py:400, invitations.py:552
  • placements.py:974 (raises Refusal, a subclass of ApiError)
  • jourfixe/rounds.py:337 (through _refuse, which builds Refused, a subclass of ApiError)
  • routes/attachments.py:100, :163, routes/board.py:82
  • routes/invitations.py:386 (returns the error instead of raising it)
  • routes/placements.py:169 (_require_open), routes/restricted.py:328, routes/tasks.py:562, :1653

Not a site: jourfixe/triage.py:416 uses project_closed as a reason string in a payload.

Proposal

  • errors.project_closed(state) -> ApiError and errors.require_open(state), which raises it when state in CLOSED_STATES. Use them at all 13 sites. routes/invitations.py:386 keeps returning the result of project_closed(state).
  • For the two subclass sites: placements.Refusal adds nothing over ApiError (tsk-j0vqtv3zhacw item 4), so placements.py:974 can raise the plain error once that lands. For jourfixe/rounds.py:337, check whether callers catch Refused specifically; if they do, keep _refuse there and use only the message builder.

Effort and risk

  • Effort S. Risk low: the same status, code and message. Tests assert on the code.

Order

  • tsk-j0vqtv3zhacw items 4 and 5 change the same placements.py:974 and routes/placements.py:166-174 (_require_open moves into placements as require_open). Do this card after them, or let that move use errors.require_open.
  • tsk-thx8zrjc708f item 10 edits attachments.bind (attachments.py:340-347) next to the first site; rebase rather than conflict.

Covered elsewhere

  • The rest of A4-10 (attachments.used/used_total, attachments_not_configured, store_of as a check): tsk-thx8zrjc708f item 10.
  • Searched: project_closed; no card covers the shared error.

Effort sum: S (1 point).

Notes

  1. Maity Coder Claude 003 · Nov 13, 2026, 23:12 UTC

    More sites from the clean-up audit (tsk-hgnbapyw7hnh, uncovered-files pass at 9dfd4b65):

    • tasks.py:562, :1653
    • board.py:82
    • restricted.py:328
    • jourfixe/rounds.py:337
    • routes/invitations.py:386