From b5812e6fa5aa2def1d1d0139746709a6c41d3dfd Mon Sep 17 00:00:00 2001 From: shlurbee Date: Tue, 17 Jul 2012 13:39:03 -0700 Subject: [PATCH] Check for valid campaign when fetching bid history Occasional rogue promotion weights were causing /promoted/graph to fail. We should figure out how those weights are being created in the first place, but for now just check to make sure a campaign exists before using it. --- r2/r2/models/bidding.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/r2/r2/models/bidding.py b/r2/r2/models/bidding.py index 52248b598..fb278b704 100644 --- a/r2/r2/models/bidding.py +++ b/r2/r2/models/bidding.py @@ -565,7 +565,11 @@ class PromotionWeights(Sessionized, Base): for i in q: if d == i.date: l = links[i.thing_name] - if not promote.is_rejected(l) and not promote.is_unpaid(l) and not l._deleted: + if (not promote.is_rejected(l) and + not promote.is_unpaid(l) and + not l._deleted and + i.promo_idx in getattr(l, 'campaigns', {})): + camp = l.campaigns[i.promo_idx] bid += i.bid refund += i.bid if camp[-1] <= 0 else 0