Skip to content

Fix UnboundLocalError in checkout endpoint (ANDROID-DN)#1379

Draft
cursor[bot] wants to merge 1 commit intomasterfrom
mainfragmentbackendapiexception-failed-to-94kw2r
Draft

Fix UnboundLocalError in checkout endpoint (ANDROID-DN)#1379
cursor[bot] wants to merge 1 commit intomasterfrom
mainfragmentbackendapiexception-failed-to-94kw2r

Conversation

@cursor
Copy link

@cursor cursor bot commented Mar 24, 2026

Summary

Fixed an UnboundLocalError in the Flask backend's /checkout endpoint that was causing HTTP 500 responses and triggering downstream errors in the Android app.

Problem

The quantities variable was being referenced in len(quantities) before it was assigned from cart['quantities']. This caused an UnboundLocalError that resulted in:

  1. Flask backend returning HTTP 500 error
  2. Android app receiving the error and throwing a MainFragment$BackendAPIException: Failed to init delivery workflow

Solution

Moved the assignment of quantities from cart['quantities'] to occur before the empty cart check.

Code Changes

Before:

if len(quantities) == 0:  # ❌ quantities not yet defined
    raise Exception("Invalid checkout request: cart is empty")

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

After:

quantities = {int(k): v for k, v in cart['quantities'].items()}
if len(quantities) == 0:  # ✅ quantities now defined
    raise Exception("Invalid checkout request: cart is empty")

Testing

  • Verified Python syntax with python3 -m py_compile
  • The fix ensures the checkout flow will proceed correctly when inventory validation is enabled

Fixes ANDROID-DN

Open in Web Open in Cursor 

…ckout

The quantities variable was being referenced in len(quantities) before
it was assigned from cart['quantities']. This caused an UnboundLocalError
that resulted in HTTP 500 responses from the /checkout endpoint.

Fixed by moving the assignment of quantities before the empty cart check.

Fixes ANDROID-DN
@vercel
Copy link
Contributor

vercel bot commented Mar 24, 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 24, 2026 6:05pm

Request Review

@idosun
Copy link
Contributor

idosun commented Mar 24, 2026

@sentry review

@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

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

Files with missing lines Patch % Lines
flask/src/main.py 0.00% 1 Missing ⚠️

❌ Your project check has failed because the head coverage (22.01%) is below the target coverage (35.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1379   +/-   ##
=======================================
  Coverage   22.01%   22.01%           
=======================================
  Files          42       42           
  Lines        1363     1363           
  Branches      176      175    -1     
=======================================
  Hits          300      300           
  Misses       1036     1036           
  Partials       27       27           
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%> (ø)

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.

2 participants