Skip to content

Commit

Permalink
Fix: imp ext prebid adunitcode unintentionally dropped (#4064)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abyfall authored Nov 21, 2024
1 parent 63af8af commit 8b757fe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion openrtb_ext/convert_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func moveRewardedFromPrebidExtTo26(i *ImpWrapper) {
// read and clear prebid ext
impExt, _ := i.GetImpExt()
rwddPrebidExt := (*int8)(nil)
if p := impExt.GetPrebid(); p != nil {
if p := impExt.GetPrebid(); p != nil && p.IsRewardedInventory != nil {
rwddPrebidExt = p.IsRewardedInventory
p.IsRewardedInventory = nil
impExt.SetPrebid(p)
Expand Down
4 changes: 2 additions & 2 deletions openrtb_ext/convert_up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,12 @@ func TestMoveRewardedFromPrebidExtTo26(t *testing.T) {
{
description: "Not Present - Null Prebid Ext",
givenImp: openrtb2.Imp{Ext: json.RawMessage(`{"prebid":null}`)},
expectedImp: openrtb2.Imp{}, // empty prebid object pruned by RebuildImp
expectedImp: openrtb2.Imp{Ext: json.RawMessage(`{"prebid":null}`)},
},
{
description: "Not Present - Empty Prebid Ext",
givenImp: openrtb2.Imp{Ext: json.RawMessage(`{"prebid":{}}`)},
expectedImp: openrtb2.Imp{}, // empty prebid object pruned by RebuildImp
expectedImp: openrtb2.Imp{Ext: json.RawMessage(`{"prebid":{}}`)},
},
{
description: "Prebid Ext Migrated To 2.6",
Expand Down
2 changes: 2 additions & 0 deletions openrtb_ext/imp.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type ExtImpPrebid struct {

Options *Options `json:"options,omitempty"`

AdUnitCode string `json:"adunitcode,omitempty"`

Passthrough json.RawMessage `json:"passthrough,omitempty"`

Floors *ExtImpPrebidFloors `json:"floors,omitempty"`
Expand Down
13 changes: 11 additions & 2 deletions openrtb_ext/request_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ func TestUserExt(t *testing.T) {

func TestRebuildImp(t *testing.T) {
var (
prebid = &ExtImpPrebid{IsRewardedInventory: openrtb2.Int8Ptr(1)}
prebidJson = json.RawMessage(`{"prebid":{"is_rewarded_inventory":1}}`)
prebid = &ExtImpPrebid{IsRewardedInventory: openrtb2.Int8Ptr(1)}
prebidJson = json.RawMessage(`{"prebid":{"is_rewarded_inventory":1}}`)
prebidWithAdunitCode = &ExtImpPrebid{AdUnitCode: "adunitcode"}
prebidWithAdunitCodeJson = json.RawMessage(`{"prebid":{"adunitcode":"adunitcode"}}`)
)

testCases := []struct {
Expand Down Expand Up @@ -220,6 +222,13 @@ func TestRebuildImp(t *testing.T) {
expectedRequest: openrtb2.BidRequest{Imp: []openrtb2.Imp{{ID: "2", Ext: prebidJson}}},
expectedAccessed: true,
},
{
description: "One - Accessed - Dirty - AdUnitCode",
request: openrtb2.BidRequest{Imp: []openrtb2.Imp{{ID: "1"}}},
requestImpWrapper: []*ImpWrapper{{Imp: &openrtb2.Imp{ID: "1"}, impExt: &ImpExt{prebid: prebidWithAdunitCode, prebidDirty: true}}},
expectedRequest: openrtb2.BidRequest{Imp: []openrtb2.Imp{{ID: "1", Ext: prebidWithAdunitCodeJson}}},
expectedAccessed: true,
},
{
description: "One - Accessed - Error",
request: openrtb2.BidRequest{Imp: []openrtb2.Imp{{ID: "1"}}},
Expand Down

0 comments on commit 8b757fe

Please sign in to comment.