Skip to content

fix: resolve competition place deduction crashes in purchasePlaces#364

Open
SiRipo92 wants to merge 28 commits intoOpenClassrooms-Student-Center:masterfrom
SiRipo92:fix/competition-places-not-deducted
Open

fix: resolve competition place deduction crashes in purchasePlaces#364
SiRipo92 wants to merge 28 commits intoOpenClassrooms-Student-Center:masterfrom
SiRipo92:fix/competition-places-not-deducted

Conversation

@SiRipo92
Copy link

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 and others added 28 commits March 13, 2026 13:39
…t, used condition to set flash message, set 200 status code and stay on index.html
fix: handle unknown email gracefully in showSummary
refactor: PEP8 fixes in show_summary - snake_case and spacing
refactor: PEP8 fixes in purchasePlaces - snake_case in function name
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: Point updates are not reflected

1 participant