diff --git a/gateway_api/tokenize/handler.py b/gateway_api/tokenize/handler.py index ba277a8..373ff54 100644 --- a/gateway_api/tokenize/handler.py +++ b/gateway_api/tokenize/handler.py @@ -89,14 +89,17 @@ def _analyze(text, language="zh"): def _resolve_customer_id(name): - # Demo-grade name -> customer_id resolution (one seeded customer, so a scan is + # Demo-grade name -> customer_id resolution (small table, so a filtered scan is # fine). Best effort: if it fails we still tokenize, just without a RAG link. + # NOTE: no `Limit` -- in DynamoDB, Limit caps items *scanned* before the filter + # runs, so `Limit=1` returns nothing when the first row scanned isn't the match + # (broke once a 2nd customer existed). A GSI on `name` would be the prod fix. if not CUSTOMERS: return None try: from boto3.dynamodb.conditions import Attr - res = CUSTOMERS.scan(FilterExpression=Attr("name").eq(name), Limit=1) + res = CUSTOMERS.scan(FilterExpression=Attr("name").eq(name)) items = res.get("Items", []) return items[0]["customer_id"] if items else None except Exception: