Fix variable scoping error in Flask checkout endpoint#223
Draft
cursor[bot] wants to merge 4 commits into
Draft
Conversation
Fixes ANDROID-GT The checkout API was checking len(quantities) before the quantities variable was defined, causing an UnboundLocalError and HTTP 500. This triggered the Android app's fallback delivery workflow exception. Fixed by defining quantities variable before checking its length.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #223 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 16 16
Lines 864 864
Branches 65 65
=====================================
Misses 864 864 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a critical variable scoping error in the Flask backend's
/checkoutendpoint that was causing HTTP 500 errors and triggering the Android app's fallback delivery workflow exception.Root Cause
In
flask/src/main.py, the checkout validation code was checkinglen(quantities) == 0before thequantitiesvariable was defined. This caused anUnboundLocalErrorwhich resulted in:BackendAPIException("Failed to init delivery workflow") via the fallbackprocessDeliveryItemfunctionChanges
quantitiesvariable definition before the length check in the checkout validation logicquantitiesis defined before being accessedBefore
After
Testing
✅ Test Results: All tests pass successfully
Run the test with:
The test verifies:
UnboundLocalErrorManual Testing
The fix resolves the issue where:
Files Changed
flask/src/main.py- Fixed variable scoping error in checkout endpoint (lines 213-214)flask/README.md- Added documentation explaining the fix and backend structureflask/test_checkout_fix.py- Added test verifying the fix works correctlyANDROID-GT-FIX-SUMMARY.md- Comprehensive fix documentationCommits
1f94586- Fix variable scoping error in checkout endpointa5d7af3- Add Flask backend documentation explaining the fix8e34cd4- Add test verifying the checkout variable scoping fixba8c225- Add comprehensive fix summary for ANDROID-GT issueFixes ANDROID-GT