Skip to content

Commit e39fec6

Browse files
authored
Merge pull request #1089 from readthedocs/davidfischer/rotations-warnings
Minor changes to logging and validation
2 parents 6721c45 + cfc86f9 commit e39fec6

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

adserver/api/serializers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ def validate_url(self, url):
124124
validator(url) # Throws ValidationError on invalid
125125
return url
126126
except ValidationError:
127-
log.warning("Invalid ad decision referring URL: %s", url)
128-
return None
127+
raise serializers.ValidationError("Invalid ad referring URL")
129128

130129
def validate_user_ip(self, ip):
131130
if ip and "," in ip:

adserver/api/views.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ def decision(self, request, data):
306306
keywords = []
307307

308308
if rotations > 1:
309-
# This is a temporary log record to see how frequently ads are rotated
310-
log.warning(
309+
log.info(
311310
"Ad rotation. rotations=%s, publisher=%s, url=%s,",
312311
rotations,
313312
publisher.slug,

adserver/tests/test_api.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,19 +1590,14 @@ def test_offer_url(self):
15901590
self.assertIsNotNone(offer)
15911591
self.assertEqual(offer.url, post_url)
15921592

1593-
# Invalid URL
1593+
# Invalid URL - rejected
15941594
self.data["url"] = "invalid-url"
15951595
resp = self.client.post(
15961596
self.url,
15971597
json.dumps(self.data),
15981598
content_type="application/json",
15991599
)
1600-
self.assertEqual(resp.status_code, 200, resp.content)
1601-
offer = Offer.objects.filter(id=resp.json()["nonce"]).first()
1602-
1603-
# Offer is accepted - URL is set to None
1604-
self.assertIsNotNone(offer)
1605-
self.assertIsNone(offer.url)
1600+
self.assertEqual(resp.status_code, 400, resp.content)
16061601

16071602
# Missing URL
16081603
del self.data["url"]

adserver/views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,11 +1122,12 @@ def ignore_tracking_reason(self, request, advertisement, offer):
11221122
log.log(self.log_level, "Ad impression for unknown publisher")
11231123
reason = "Unknown publisher"
11241124
elif not advertisement.flight.show_to_geo(geo_data):
1125-
# This is very rare but it is visible in ad reports
1125+
# Check again that the geo-targeting matches
11261126
# I believe the most common cause for this is somebody uses a VPN and is served an ad
11271127
# Then they turn off their VPN and click on the ad
1128+
# These should not be billed to advertisers and can be safely ignored.
11281129
log.log(
1129-
self.log_security_level,
1130+
self.log_level,
11301131
"Invalid geo targeting for ad [%s]. Country: [%s], Region: [%s], Metro: [%s]",
11311132
advertisement,
11321133
geo_data.country,

0 commit comments

Comments
 (0)