Skip to content

Commit cb45bf6

Browse files
stsewdericholscher
authored andcommitted
Analytics: Don't use full_path in get_or_create (#9099)
We have old records without `full_path`, and since `full_path` isn't in the constraints of `unique_together` Django will try to create a new record with that value and fail. This isn't a problem for new page views.
1 parent 66b4109 commit cb45bf6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

readthedocs/analytics/models.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def _last_30_days_iter():
2222

2323

2424
class PageViewManager(models.Manager):
25+
26+
"""Manager for PageView model."""
27+
2528
def register_page_view(self, project, version, path, full_path, status):
2629
# Normalize paths to avoid duplicates.
2730
path = "/" + path.lstrip("/")
@@ -31,10 +34,12 @@ def register_page_view(self, project, version, path, full_path, status):
3134
project=project,
3235
version=version,
3336
path=path,
34-
full_path=full_path,
3537
date=timezone.now().date(),
3638
status=status,
37-
defaults={"view_count": 1},
39+
defaults={
40+
"view_count": 1,
41+
"full_path": full_path,
42+
},
3843
)
3944
if not created:
4045
page_view.view_count = models.F("view_count") + 1

0 commit comments

Comments
 (0)