{"action":"closed","issue":{"url":"https://api.github.com/repos/prebid/prebid-server/issues/700","repository_url":"https://api.github.com/repos/prebid/prebid-server","labels_url":"https://api.github.com/repos/prebid/prebid-server/issues/700/labels{/name}","comments_url":"https://api.github.com/repos/prebid/prebid-server/issues/700/comments","events_url":"https://api.github.com/repos/prebid/prebid-server/issues/700/events","html_url":"https://github.com/prebid/prebid-server/issues/700","id":363753871,"node_id":"MDU6SXNzdWUzNjM3NTM4NzE=","number":700,"title":"jsonpatch.MergePatch silently failing in processStoredRequests() in endpoints/openrtb2/auction","user":{"login":"afsheenb","id":2190119,"node_id":"MDQ6VXNlcjIxOTAxMTk=","avatar_url":"https://avatars3.githubusercontent.com/u/2190119?v=4","gravatar_id":"","url":"https://api.github.com/users/afsheenb","html_url":"https://github.com/afsheenb","followers_url":"https://api.github.com/users/afsheenb/followers","following_url":"https://api.github.com/users/afsheenb/following{/other_user}","gists_url":"https://api.github.com/users/afsheenb/gists{/gist_id}","starred_url":"https://api.github.com/users/afsheenb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afsheenb/subscriptions","organizations_url":"https://api.github.com/users/afsheenb/orgs","repos_url":"https://api.github.com/users/afsheenb/repos","events_url":"https://api.github.com/users/afsheenb/events{/privacy}","received_events_url":"https://api.github.com/users/afsheenb/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-09-25T20:30:55Z","updated_at":"2018-10-01T12:41:00Z","closed_at":"2018-10-01T12:41:00Z","author_association":"NONE","body":"Hello,\r\n\r\nI'm testing stored requests with the http endpoint at the moment, and running into a subtle bug that's stopping me from continuing my tests.\r\n\r\nDefined in my pbs.yaml:\r\n\r\n```stored_requests:\r\n  http:\r\n    endpoint: http://test-http.testdomain.com:8081/reqs\r\n    amp_endpoint: http://test-http.testdomain.com:8081/reqs?amp=true\r\n  in_memory_cache:\r\n    ttl_seconds: 300 # 5 minutes\r\n    request_cache_size_bytes: 107374182 # 0.1GB\r\n    imp_cache_size_bytes: 107374182 # 0.1GB\r\n```\r\n\r\nA test request and response sent to the `http://test-dev.testdomain.com:8081/reqs` endpoint:\r\n\r\ncurl request:\r\n\r\n```\r\ncurl \"http://test-http.testdomain.com:8081/reqs?imp-ids=\\[\\\"imp1\\\"\\]\"\r\n``` \r\nResponse:\r\n```\r\n{\"imps\": {\"imp1\": \"{ \\\"banner\\\": { \\\"format\\\": [ { \\\"w\\\": 300, \\\"h\\\": 250 } ] }, \\\"ext\\\": { \\\"appnexus\\\": { \\\"placementId\\\": \\\"123456\\\" } } }\"}}\r\n```\r\n\r\n\r\nSo far so good. If I were to send a test request to my prebid-server instance with the following payload:\r\n\r\n```\r\ncurl 'http://test-pbs.testdomain.com/openrtb2/auction' --data-binary '{ \"id\": \"test-request-id\", \"imp\": [ { \"id\": \"test-imp\", \"ext\": { \"prebid\": { \"storedrequest\": { \"id\": \"imp1\" } } } } ], \"site\":{\"page\":\"http://demo.the-test-prebid-page.com\"}}'`\r\n```\r\n\r\nI would expect the data returned by the `http://test-http.testdomain.com:8081` endpoint to be merged with the data in the test request. However, it's failing to merge, and instead I'm receiving this error:\r\n\r\n```\r\nInvalid request: request.imp[0] must contain at least one of \"banner\", \"video\", \"audio\", or \"native\"\r\n```\r\n...because the `banner` key is in the stored request that's failing to be merged.\r\n\r\n I've confirmed that the issue is happening with jsonpatch.Mergepatch by adding the following lines in the processStoredRequests() function to print out the json being merged:\r\n\r\n```        // Apply any Stored Imps, if they exist. Since the JSON Merge Patch overrides arrays,\r\n        // and Prebid Server defers to the HTTP Request to resolve conflicts, it's safe to\r\n        // assume that the request.imp data did not change when applying the Stored BidRequest.\r\n        for i := 0; i < len(impIds); i++ {\r\n                resolvedImp, err := jsonpatch.MergePatch(storedImps[impIds[i]], imps[idIndices[i]])\r\n                if err != nil {\r\n                        return nil, []error{err}\r\n                }\r\n                printStoredImp, _ := json.Marshal(storedImps[impIds[i]])\r\n                fmt.Println(\"Stored Imp:\")\r\n                fmt.Println(string(printStoredImp))\r\n\r\n                printStoredImpIndice, _ := json.Marshal(imps[idIndices[i]])\r\n                fmt.Println(\"Imp Id Index:\")\r\n                fmt.Println(string(printStoredImpIndice))\r\n\r\n                printResolvedImp, _ := json.Marshal(resolvedImp)\r\n                fmt.Println(\"Resolved Imp:\")\r\n                fmt.Println(string(printResolvedImp))\r\n\r\n                imps[idIndices[i]] = resolvedImp\r\n```\r\n\r\nCompiling with these lines added and sending a test request, I see the following logged:\r\n\r\nStored Imp:\r\n```\r\n\"{ \\\"banner\\\": { \\\"format\\\": [ { \\\"w\\\": 300, \\\"h\\\": 250 } ] }, \\\"ext\\\": { \\\"appnexus\\\": { \\\"placementId\\\": \\\"123456\\\" } } }\"\r\n```\r\nImp Id Index:\r\n```\r\n{\"id\":\"test-imp\",\"ext\":{\"prebid\":{\"storedrequest\":{\"id\":\"imp1\"}}}}\r\n```\r\nResolved Imp:\r\n```\r\n\"eyJleHQiOnsicHJlYmlkIjp7InN0b3JlZHJlcXVlc3QiOnsiaWQiOiJpbXAxIn19fSwiaWQiOiJ0ZXN0LWltcCJ9\"\r\n```\r\nSo - `storedImps[impIds[i]]` holds our stored request data in JSON format, successfully retrieved from our HTTP endpoint;  `imps[idIndices[i]]` holds the data for the imp[i] object sent in the request, but `resolvedImp` is set to `eyJleHQiOnsicHJlYmlkIjp7InN0b3JlZHJlcXVlc3QiOnsiaWQiOiJpbXAxIn19fSwiaWQiOiJ0ZXN0LWltcCJ9`, which is just the base64 encoded JSON string `{\"ext\":{\"prebid\":{\"storedrequest\":{\"id\":\"imp1\"}}},\"id\":\"test-imp\"}`.\r\n\r\nEven though the JSON for the stored Imp seems to be valid, and no error is thrown during the jsonpatch.MergePatch() call, the JSON apparently isn't being merged successfully, and instead the MergePatch() is silently failing. \r\n\r\nI've tried removing the quotes from the JSON object returned by the HTTP endpoint with no change; I'm not sure if there's a snafu with the format that the stored request is in (which appears to be valid JSON), or if this is a bug of some sort. \r\n\r\nPlease advise.\r\n\r\nThanks,\r\n\r\n--afsheenb"}}
{"actor":{"display_login":"dbemiller"}}