pizzapi icon indicating copy to clipboard operation
pizzapi copied to clipboard

Fix: Skip missing products in menu categorization instead of raising exception

Open dmcgill50 opened this issue 4 months ago • 0 comments

Problem

The library currently crashes when calling store.get_menu() with this error:

Exception: PRODUCT NOT FOUND: 9413 CouponPizza

This affects many users as evidenced by issues #115, #125, #119, and others.

Root Cause

The Domino's API sometimes references product codes in the Categorization section that don't exist in the Products, Coupons, or PreconfiguredProducts dictionaries. These are phantom references to items that may be:

  • Excluded from the current store
  • Unsupported in certain regions
  • Temporarily unavailable
  • No longer offered

Solution

Changed pizzapi/menu.py line 66 to gracefully skip missing products instead of raising an exception:

# Before
if product_code not in self.menu_by_code:
    raise Exception('PRODUCT NOT FOUND: %s %s' % (product_code, category.code))

# After  
if product_code not in self.menu_by_code:
    # Skip products that don't exist in the menu data
    # This handles phantom references and excluded/unavailable items
    continue

Testing

Tested with multiple Domino's stores that previously failed:

✅ Menu objects now create successfully ✅ Order objects can be instantiated ✅ Items can be added to orders ✅ The library is functional end-to-end

Example test:

from pizzapi import Address, Customer, Order, Store

address = Address('700 Pennsylvania Avenue', 'Washington', 'DC', '20408')
store = address.closest_store()

# This now works (previously crashed)
customer = Customer('Test', 'User', '[email protected]', '5555555555')
order = Order(store, customer, address)
order.add_item('12SCREEN')  # Medium Hand Tossed Pizza

Impact

  • Fixes issues: #115, #125, #119, and related "PRODUCT NOT FOUND" errors
  • Backward compatible: Existing working code continues to work
  • No breaking changes: Only affects error case
  • Minimal code change: 2 lines changed, maintains existing logic

Why This Approach

This is the safest fix because:

  1. Graceful degradation - Menu loads with available items only
  2. No side effects - Missing items simply aren't included in categories
  3. Maintains functionality - All other menu operations work normally
  4. Future-proof - Handles API changes without crashing

Alternative approaches would require:

  • Parsing Variants into menu_by_code (larger refactor)
  • Checking ExcludedProducts everywhere (more complex)
  • Hardcoding exceptions (not maintainable)

Related Issues

Closes #115 Closes #125
Closes #119

May also fix #122, #69, and #59 which report similar menu loading issues.

dmcgill50 avatar Oct 08 '25 10:10 dmcgill50