Skip to content

feat(api): enforce squad number immutability on PUT#532

Merged
nanotaboada merged 1 commit intomasterfrom
feat/put-squad-number-mismatch-validation
Mar 21, 2026
Merged

feat(api): enforce squad number immutability on PUT#532
nanotaboada merged 1 commit intomasterfrom
feat/put-squad-number-mismatch-validation

Conversation

@nanotaboada
Copy link
Owner

@nanotaboada nanotaboada commented Mar 21, 2026

Summary

  • Add mismatch guard in put_async: if squad_number in the request body
    does not match the path parameter, return HTTP 400 Bad Request
  • Document the single-model design decision in PlayerRequestModel module
    docstring, explaining why one model covers both POST and PUT
  • Add test test_request_put_player_squadnumber_mismatch_response_status_bad_request

Test plan

  • PUT /players/squadnumber/23 with body squadNumber: 999 → 400 Bad Request
  • PUT /players/squadnumber/23 with body squadNumber: 23 → 204 No Content
  • PUT /players/squadnumber/999 (unknown) with matching body → 404 Not Found
  • PUT /players/squadnumber/23 with empty body → 422 Unprocessable Entity
  • All existing tests pass, coverage remains at 100%

Closes #529

🤖 Generated with Claude Code


This change is Reviewable

Summary by CodeRabbit

  • Bug Fixes
    • Updated the player update endpoint to validate that the squad number in the request body matches the squad number in the URL path, returning a 400 Bad Request if they differ for improved data consistency and clearer error messaging.

Add a mismatch guard in put_async: if squad_number in the request
body does not match the path parameter, return HTTP 400 Bad Request.
The path parameter is the authoritative source of identity on PUT.

Document the single-model design decision in PlayerRequestModel:
one model intentionally covers both POST and PUT, with per-operation
differences handled at the route layer.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c8c69a2d-f880-4ac3-8b5e-e9ca71ddd187

📥 Commits

Reviewing files that changed from the base of the PR and between 2beb177 and c8360c5.

📒 Files selected for processing (3)
  • models/player_model.py
  • routes/player_route.py
  • tests/test_main.py

Walkthrough

The PR adds validation to the PUT /players/squadnumber/{squad_number} endpoint to enforce that the squad_number field in the request body must match the path parameter value. If they mismatch, a 400 Bad Request is returned. Module-level documentation and test coverage were added to clarify this behavior.

Changes

Cohort / File(s) Summary
Documentation & Validation
models/player_model.py, routes/player_route.py
Added module documentation explaining design decision to reuse PlayerRequestModel for both POST and PUT, with operation-specific rules enforced at route layer. Implemented mismatch guard in PUT endpoint that validates player_model.squad_number matches path parameter squad_number, returning 400 Bad Request if they differ.
Test Coverage
tests/test_main.py
Added test test_request_put_player_squadnumber_mismatch_response_status_bad_request that verifies 400 Bad Request response when request body squad_number differs from path parameter.

Assessment against linked issues

Objective Addressed Explanation
PUT returns 400 if squad_number in body does not match path parameter [#529]
PlayerRequestModel remains unchanged [#529]
New test covers the mismatch case [#529]

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • #524: Both PRs modify the PUT /players/squadnumber/{squad_number} endpoint; this PR adds mismatch validation while the related PR refactors the endpoint to use squad_number as the mutation key.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits format with 'feat:' prefix, is descriptive and specific about enforcing squad number immutability on PUT operations, and is well under the 80-character limit at 51 characters.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📋 Issue Planner

Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).

View plan for ticket: #529

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/put-squad-number-mismatch-validation
  • 🛠️ sync documentation: Commit on current branch
  • 🛠️ sync documentation: Create PR
  • 🛠️ enforce http error handling: Commit on current branch
  • 🛠️ enforce http error handling: Create PR
  • 🛠️ idiomatic review: Commit on current branch
  • 🛠️ idiomatic review: Create PR
  • 🛠️ verify api contract: Commit on current branch
  • 🛠️ verify api contract: Create PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link

@nanotaboada nanotaboada merged commit 24da552 into master Mar 21, 2026
9 checks passed
@nanotaboada nanotaboada deleted the feat/put-squad-number-mismatch-validation branch March 21, 2026 22:06
@codecov
Copy link

codecov bot commented Mar 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2beb177) to head (c8360c5).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #532   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          111       113    +2     
=========================================
+ Hits           111       113    +2     
Components Coverage Δ
Services 100.00% <ø> (ø)
Routes 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

[FEATURE] Enforce squad number immutability on PUT

1 participant