Skip to content

Commit

Permalink
Fix: BidRequest updated by ProcessedAuction hook is getting overridde…
Browse files Browse the repository at this point in the history
…n by requestwrapper utility (#3045)
  • Loading branch information
pm-nikhil-vaidya authored Sep 7, 2023
1 parent ea079a9 commit 9980b64
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion hooks/hookexecution/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (e *hookExecutor) ExecuteProcessedAuctionStage(request *openrtb_ext.Request

stageName := hooks.StageProcessedAuctionRequest.String()
executionCtx := e.newContext(stageName)
payload := hookstage.ProcessedAuctionRequestPayload{BidRequest: request.BidRequest}
payload := hookstage.ProcessedAuctionRequestPayload{RequestWrapper: request}

outcome, _, contexts, reject := executeStage(executionCtx, plan, payload, handler, e.metricEngine)
outcome.Entity = entityAuctionRequest
Expand Down
14 changes: 11 additions & 3 deletions hooks/hookexecution/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (e mockTimeoutHook) HandleProcessedAuctionHook(_ context.Context, _ hooksta
time.Sleep(20 * time.Millisecond)
c := hookstage.ChangeSet[hookstage.ProcessedAuctionRequestPayload]{}
c.AddMutation(func(payload hookstage.ProcessedAuctionRequestPayload) (hookstage.ProcessedAuctionRequestPayload, error) {
payload.BidRequest.User.CustomData = "some-custom-data"
payload.RequestWrapper.User.CustomData = "some-custom-data"
return payload, nil
}, hookstage.MutationUpdate, "bidRequest", "user.customData")

Expand Down Expand Up @@ -305,12 +305,20 @@ func (e mockUpdateBidRequestHook) HandleProcessedAuctionHook(_ context.Context,
c := hookstage.ChangeSet[hookstage.ProcessedAuctionRequestPayload]{}
c.AddMutation(
func(payload hookstage.ProcessedAuctionRequestPayload) (hookstage.ProcessedAuctionRequestPayload, error) {
payload.BidRequest.User.Yob = 2000
payload.RequestWrapper.User.Yob = 2000
userExt, err := payload.RequestWrapper.GetUserExt()
if err != nil {
return payload, err
}
newPrebidExt := &openrtb_ext.ExtUserPrebid{
BuyerUIDs: map[string]string{"some": "id"},
}
userExt.SetPrebid(newPrebidExt)
return payload, nil
}, hookstage.MutationUpdate, "bidRequest", "user.yob",
).AddMutation(
func(payload hookstage.ProcessedAuctionRequestPayload) (hookstage.ProcessedAuctionRequestPayload, error) {
payload.BidRequest.User.Consent = "true"
payload.RequestWrapper.User.Consent = "true"
return payload, nil
}, hookstage.MutationUpdate, "bidRequest", "user.consent",
)
Expand Down
8 changes: 4 additions & 4 deletions hooks/hookstage/processedauctionrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package hookstage
import (
"context"

"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/openrtb_ext"
)

// ProcessedAuctionRequest hooks are invoked after the request is parsed
Expand All @@ -23,8 +23,8 @@ type ProcessedAuctionRequest interface {
) (HookResult[ProcessedAuctionRequestPayload], error)
}

// ProcessedAuctionRequestPayload consists of the openrtb2.BidRequest object.
// Hooks are allowed to modify openrtb2.BidRequest using mutations.
// ProcessedAuctionRequestPayload consists of the openrtb_ext.RequestWrapper object.
// Hooks are allowed to modify openrtb_ext.RequestWrapper using mutations.
type ProcessedAuctionRequestPayload struct {
BidRequest *openrtb2.BidRequest
RequestWrapper *openrtb_ext.RequestWrapper
}

0 comments on commit 9980b64

Please sign in to comment.