-
Notifications
You must be signed in to change notification settings - Fork 768
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
Adform adapter lacked gross/net parameter support #2084
Conversation
…Type as in client adapter.
@braizhas maybe you want to have a look at this as well. |
} | ||
} else { | ||
requestExt = adfRequestExt{} | ||
} |
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.
else
statement can be omitted if you init requestExt like this: requestExt := adfRequestExt{}
(line 57)
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! It will be initiated even if it may not be needed but no harm done in that I guess.
requestExt.PriceType = adfImpExt.PriceType | ||
|
||
var err error | ||
if request.Ext, err = json.Marshal(&requestExt); err != 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.
Line 60: you marshal req.Ext as many times as many imps are there in reqiest - it's located inside for _, imp := range request.Imp {
. This should be moved ouside the for loop.
Line 71 sets new request.ext on every iteration over imp array. It means req.ext.PriceType
will have the value from last imp in loop.
How will it work on your side if there are two or more imp in request with different PriceType
?
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.
All priceTypes need to be the same, but really only the first one should be used and not the last one if they should differ.
I took a bad shortcut there. Me programming Go is also a bit like https://youtu.be/C1Sw0PDgHU4.
"bidder": { | ||
"mid": "828782", | ||
"priceType": "gross" | ||
} |
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.
Please add a test case where there are 2 imps in request with different priceType
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.
Not sure if that is really needed but I can add one.
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.
Done. Thank you @VeronikaSolovei9 for the feedback!
Please update adapter documentation with the description of new parameter |
|
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.
Thank you for the fixes, LGTM :)
@bjorn-lw thanks for the notification. Please also update |
Fixed, thank you! |
adapters/adf/adf.go
Outdated
requestExt.PriceType = priceType | ||
|
||
var err error | ||
if request.Ext, err = json.Marshal(&requestExt); err != 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.
At this point, you are remarshalling requestExt
, which may not be properly populated if the above unmarshal failed. This should be very unlikely, perhaps impossible, but you may want to consider if you want the request to progress through this stage if an error happened.
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.
@hhhjort Thanks! It should be be fixed, but I don't like the many nested if's. I would probably have done it a little different in a language I'm more familiar with. If you can give me a hint on how to make it look nicer, please do.
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.
Actually this doesn't fix it. If you hit line 69, having encountered and error with unmarshalling the .ext
, you still drop down and overwrite the original .ext
on line 75. You would have to break out of the section, perhaps returning an error from MakeRequests()
at that line, to avoid this issue. I am not terribly concerned with this, as it is something that should really never happen in the first place. And if it does somehow happen, it just means that the request.ext
you are sending to your server may have missing/corrupt data in it. I really just wanted to highlight it so you could decide if it is a worry for you and change your handling if it is. If you reply that you are good with it as is, or just do nothing, I am still good with approving this PR. Just giving you some time to respond before it is merged.
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.
Ack, nevermind, it does fix it. I just did not read the code properly.
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.
@hhhjort I was frantically reading trying to understand what I missed :) But I think the code is ugly. Can it be written better? You don't have to reply, I could take that online course on Go if I can just get some additional hours in a day :)
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 don't have any specific recommendations to make this code prettier, it seems normal enough go to me. Well, one thing that might improve the view...
In the initial loop where you try to find the price type, you are only interested in the first value you find. So when you do find it, you could instead call setRequestPriceType(request *openrtb2.BidRequest, priceType string)
, which would be the following block of code that sets the price type in request.ext
. Then in that function, you could return immediately if the unmarshal fails, making it more obvious that a failure aborts the rest of price type processing. Moving the code to its own function isolates it as its own step, leaving the main function cleaner in its logic. You coud also put the loop to find the price type in the function, making it easier to break out of the loop and further focusing the main function's code.
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.
@hhhjort yes, common clean code sense. I may leave it as is for now if you don't mind. I might get back to this at a later time if I come up with something else that needs to be done in the adapter. Is that OK?
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.
That is fine, I have already approved this PR
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
* 'master' of https://github.com/wwwyyy/prebid-server: (23 commits) Add GPID Reserved Bidder Name (prebid#2107) Marsmedia adapter - param zoneId can get string and int (prebid#2105) Algorix: add Server Region Support (prebid#2096) New Adapter: Bizzclick (prebid#2056) Collect Prometheus Go process metrics (prebid#2101) Added channel support (prebid#2037) Rubicon: update fpd fields resolving (prebid#2091) Beachfront - Currency conversion (prebid#2078) New Adapter: Groupm (Alias Of PubMatic) (prebid#2042) Adform adapter lacked gross/net parameter support (prebid#2084) add iframe sync for openx (prebid#2094) changes to the correct user sync url (prebid#2092) Smaato: Add instl to tests (prebid#2089) Correct MakeRequests() output assertion in adapter JSON tests (prebid#2087) Adview: adapter currency fix. (prebid#2060) New Adapter: Coinzilla (prebid#2074) Syncer Level ExternalURL Override (prebid#2072) 33Across: Enable Support for SRA requests (prebid#2079) Currency conversion on adapter JSON tests (prebid#2071) New Adapter: VideoByte (prebid#2058) ...
The client version of the Adform adapter supports choosing between returning gross or net via the priceType parameter.
As the new "adf" adapter defaults to net while the old "adform" adapter defaulted to gross, this can make the transition to the new adapter become quite a challenge if you are using plenty of bid conversion functions and the PBS adapter doesn't support selecting gross or net.
This PR adds the same priceType support as the client has.