Skip to content
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 imp ext prebid adunitcode drop #4064

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This is an optimization unrelated to the fix.

Functionally, it doesn't matter if IsRewardedInventory is nil in the ext since it's always set to nil in the upconvert process. There is a side affect that calling SetPrebid will eventually force a re-marshal, so if there is no change then it's a slight performance optimization to skip.

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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This is the fix. For some reason, this supported prebid extension was not adde to the structure which caused it to be ignored when marshalling this struct. Confirmed all other imp[].ext.prebid values from the docs are included here.


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
Loading