-
Notifications
You must be signed in to change notification settings - Fork 738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Panic in bid adjustments #3547
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the test to confirm the fix. I have just one minor suggestion. Let me know your thoughts.
bidadjustment/build_rules.go
Outdated
@@ -63,7 +63,7 @@ func merge(req *openrtb_ext.RequestWrapper, acct *openrtb_ext.ExtRequestPrebidBi | |||
if extPrebid == nil && acct == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on changing this logic? I'm thinking it might be easier to understand if it were like this:
if (extPrebid == nil || extPrebid.BidAdjustments == nil) {
if acct == nil {
return nil, nil
}
return acct, nil
}
if acct == nil {
return extPrebid.BidAdjustments, nil
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if extPrebid == nil || extPrebid.BidAdjustments == nil {
return acct, nil
}
if acct == nil {
return extPrebid.BidAdjustments, nil
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
bidadjustment/build_rules.go
Outdated
@@ -63,7 +63,7 @@ func merge(req *openrtb_ext.RequestWrapper, acct *openrtb_ext.ExtRequestPrebidBi | |||
if extPrebid == nil && acct == nil { | |||
return nil, nil | |||
} | |||
if extPrebid == nil && acct != nil { | |||
if (extPrebid == nil || extPrebid.BidAdjustments == nil) && acct != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 3rd test case in the truth table below seems to still panic under the newly added logic. Do you agree?
| extPrebid | extPrebid.BidAdjustments | acct || returns
---|-----------|--------------------------|---------||-----------
1| nil | nil | nil || nil, nil
2| nil | nil | not-nil || acct, nil
3| not-nil | nil | nil || PANIC in line 73 when dereferencing nil extPrebid.BidAdjustments
4| not-nil | nil | not-nil || acct, nil
5| not-nil | not-nil | nil || extPrebid.BidAdjustments, nil
6| not-nil | not-nil | not-nil || acct, nil
I believe the modification below could cover the panic scenario but I think, as written below, we have repetitive checks:
62
63 if extPrebid == nil && acct == nil {
64 return nil, nil
65 }
66 if (extPrebid == nil || extPrebid.BidAdjustments == nil) && acct != nil {
67 return acct, nil
68 }
69 - if extPrebid != nil && acct == nil {
+ if extPrebid != nil && extPrebid.BidAdjustments != nil && acct == nil {
70 return extPrebid.BidAdjustments, nil
71 }
+ if extPrebid != nil && extPrebid.BidAdjustments == nil {
+ extPrebid.BidAdjustments := &ExtRequestPrebidBidAdjustments{}
+ }
72
73 extPrebid.BidAdjustments.MediaType.Banner = mergeForMediaType(extPrebid.BidAdjustments.MediaType.Banner, acct.MediaType.Banner)
// PANIC deferencing null ^
// pointer in scenario 3 |
// if we don't modify ----+
bidadjustment/build_rules.go
Honestly, the modifications proposed by you and Brian Sardo above, seem a lot better than I just proposed here. Can we please put logic between lines 63 to 71 in its own function, refactor as necessary, and unit test all the scenarios?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guscarreon I added 6 test cases for your table, there is no panic
"dealId": []openrtb_ext.Adjustment{{Type: AdjustmentTypeCPM, Value: 3}}, | ||
}, | ||
}, | ||
VideoOutstream: map[openrtb_ext.BidderName]openrtb_ext.AdjustmentsByDealID{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Just to make the test case less verbose, can we remove some of the elements so we are only left with bidder "bidderA"
and "bidderB"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's necessary to test all media types banner|video-instream|video-outstream|audio|native|*
}, | ||
}, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: can we remove the extra space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed extra line breaks, the next removal will lead to poor readability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry for the confusion. By extra space I meant line 435 only. I was ok with the rest of the line breaks. I agree that removing them leads to poor readability. I'll approve anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you @linux019 for addressing my feedback
If auction request doesn't have bidadjustments object, but the adjustment has been enabled in the stored requests for the account there will be a panic
#3543