Skip to content

Fix/competition places not deducted#12

Merged
SiRipo92 merged 8 commits intoQAfrom
fix/competition-places-not-deducted
Mar 13, 2026
Merged

Fix/competition places not deducted#12
SiRipo92 merged 8 commits intoQAfrom
fix/competition-places-not-deducted

Conversation

@SiRipo92
Copy link
Owner

Closes #6

Problem

purchasePlaces() crashed with IndexError 500 when competition or club
names from the form did not match the database. [0] was called on an
empty list with no error handling, making the function unreachable in
error scenarios.

Root Cause

Two instances of [0] list indexing assumed a match would always be found:
competition = [c for c in competitions if c['name'] == ...][0]
club = [c for c in clubs if c['name'] == ...][0]

Fix

  • Replaced [0] with next() and None default for both competition and club
  • Added guard clause: if not competition or not club flash error and
    redirect to welcome.html keeping the user logged in
  • PEP8: placesRequired → places_required, added spaces around operator

Tests

  • HAPPY PATH: valid booking deducts places from competition
  • HAPPY PATH: updated count reflected immediately in memory
  • SAD PATH: unknown competition returns error without crashing
  • SAD PATH: unknown club returns error without crashing
  • EDGE CASE/ CHARACTERISATION: numberOfPlaces type consistency after deduction

@SiRipo92 SiRipo92 merged commit 0ed505d into QA Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Competition places are not correctly deducted after booking

1 participant