Skip to content

Fix NameError in checkout endpoint - Fixes ANDROID-DN#1388

Draft
cursor[bot] wants to merge 1 commit intomasterfrom
mainfragmentbackendapiexception-failed-to-2g30sm
Draft

Fix NameError in checkout endpoint - Fixes ANDROID-DN#1388
cursor[bot] wants to merge 1 commit intomasterfrom
mainfragmentbackendapiexception-failed-to-2g30sm

Conversation

@cursor
Copy link

@cursor cursor bot commented Mar 26, 2026

Problem

The Flask backend's /checkout endpoint was causing a NameError by attempting to use the quantities variable before it was defined. This resulted in:

  1. A 500 Internal Server Error from the Flask backend
  2. The Android app receiving the error and throwing MainFragment$BackendAPIException: Failed to init delivery workflow

Root Cause

In flask/src/main.py line 225, the code checked len(quantities) before quantities was assigned on line 228:

# Before fix
if len(quantities) == 0:  # Line 225 - NameError!
    raise Exception("Invalid checkout request: cart is empty")

quantities = {int(k): v for k, v in cart['quantities'].items()}  # Line 228

Solution

Moved the quantities assignment before the length check:

# After fix
quantities = {int(k): v for k, v in cart['quantities'].items()}  # Line 225
if len(quantities) == 0:  # Line 226 - Now works!
    raise Exception("Invalid checkout request: cart is empty")

Impact

  • Fixes ANDROID-DN
  • The checkout flow will now properly validate inventory without throwing a NameError
  • The backend will return proper responses instead of 500 errors
  • The Android app will no longer throw BackendAPIException due to this backend error

Testing

✅ Python syntax validation passed
✅ Logic verification test passed
✅ The fix addresses the order-of-operations issue

When a checkout request is made with validate_inventory: true, the endpoint will now:

  1. Properly parse the cart quantities
  2. Validate the cart is not empty
  3. Process inventory checks correctly
  4. Return appropriate success/failure responses
Open in Web Open in Cursor 

Fixes ANDROID-DN

The checkout endpoint was attempting to check len(quantities) before
quantities was assigned, causing a NameError and 500 response. This
error propagated to the Android app which threw BackendAPIException.

Fixed by moving the quantities assignment from line 228 to line 225,
before the length check.
@vercel
Copy link
Contributor

vercel bot commented Mar 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
empower Ignored Ignored Mar 26, 2026 3:42pm

Request Review

@codecov
Copy link

codecov bot commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 22.01%. Comparing base (4272cc5) to head (5de2dbf).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
flask/src/main.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1388   +/-   ##
=======================================
  Coverage   22.01%   22.01%           
=======================================
  Files          42       42           
  Lines        1363     1363           
  Branches      176      176           
=======================================
  Hits          300      300           
- Misses       1036     1037    +1     
+ Partials       27       26    -1     
Flag Coverage Δ
api 5.82% <0.00%> (ø)
frontend 32.37% <ø> (ø)
Components Coverage Δ
checkout_module 5.82% <0.00%> (ø)
product_component 26.03% <ø> (ø)
Files with missing lines Coverage Δ
flask/src/main.py 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

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.

1 participant