Skip to content

Commit 52cf3ee

Browse files
authored
Fix AttributeError when build.version is None in telemetry collection (#12572)
## Summary Fixes an AttributeError that occurs when collecting telemetry data for builds where the version has been deleted. ## Details The `Build.version` field is nullable (`null=True`, `on_delete=models.SET_NULL`), which means it can be `None` when a version is deleted. The telemetry data collection code was attempting to access `build.version.id` without checking for `None`, causing an AttributeError. ## Fixes https://read-the-docs.sentry.io/issues/6296397769/
1 parent d8e8215 commit 52cf3ee

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

readthedocs/telemetry/models.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ def collect(self, build, data):
9393
"success": build.success,
9494
}
9595
data["project"] = {"id": build.project.id, "slug": build.project.slug}
96-
data["version"] = {
97-
"id": build.version.id,
98-
"slug": build.version.slug,
99-
}
96+
if build.version:
97+
data["version"] = {
98+
"id": build.version.id,
99+
"slug": build.version.slug,
100+
}
100101
org = build.project.organizations.first()
101102
if org:
102103
data["organization"] = {

0 commit comments

Comments
 (0)