Coupon 90000008 never applied on dev

A free-shipping coupon edited in the coupon admin never took effect on dev. Three unrelated faults stacked up, each of which alone was enough to produce “the coupon does nothing”.

What was wrong

A crash on the nationwide cache hit path. NationwideCalculator.price built its result with the cache key’s field names instead of the schema’s:

NationwideCost(postcode=..., weight=..., shippingMode=...)   # schema is maxW / cost / nationwideMode

This threw inside order.toDict(), and calculatecost2 caught it and fell back to the legacy resolve-coupon-master path. The fallback returns a valid-looking response with an empty couponCodeList, so the failure surfaced as “coupon rejected” rather than as an error. Nationwide carts could never apply a VillaCoupon3 code.

Lambda init timeouts. calculatecost3/app.py imported the calculator at module scope, pulling pandas/numpy/pyarrow past Lambda’s 10 second init limit. Fixed by importing lazily inside the handler.

The website was calling the wrong calculators. /api/calculatePrice/getCost fell through CloudFront’s catch-all to the 2021 calculator, and the frontend hardcoded the master API m4q33ulvm9 for coupon pricing. Neither is wired to villacoupon3.

Why “the fix isn’t there yet” persisted after the fix

The backend was verified correct while testers still saw the old behaviour. The service worker was serving a precached copy of the old bundle. A corrected file in S3 and a completed CloudFront invalidation are not sufficient — the Workbox precache manifest pins each asset to a revision hash, and until that hash changes the worker ignores the network.

This cost more time than any of the actual bugs. It is now written up in patch-dev-web-bundle.

Fixes

ChangeWhere
NationwideCost built with correct kwargssrc/calculateCost2/shipping/nationwidePrice.py
Lazy import of the real handlercalculatecost3/app.py
CloudFront behavior getCost*calculatecost2newdev distribution E200VHSCVLY8TL
Frontend cost endpoint made relativedev bundle (later villaEcommerceWeb#315)
Precache revision bumped, service worker cache-busteds3://dev.villamarket.net

Verification

Micky’s exact payload through the dev CloudFront route:

couponCodeList ["90000008"] · isFreeShipping true · deliveryFee 115
shippingDiscount 115 · discountedDeliveryFee 0 · grandTotal 6715

In the browser, applying the code on a nationwide checkout showed a shipping discount and zeroed the delivery fee, with no request to m4q33ulvm9.

Worth remembering

A silent fallback is worse than a crash. The resolve-coupon-master fallback turned a schema mismatch into a plausible-looking empty result, which sent the investigation towards coupon configuration instead of towards an exception. Log loudly when a fallback fires.

Aung’s read at the time — “it is not cloudfront or coupon, it’s a calculatecost2 infrastructure issue” — was right about the init timeout and saved a lot of time. The nationwide crash was a second, independent fault underneath it.