Skip to content

Commit ace8325

Browse files
committed
Fix bug in notifications
If an exception is raised before setting the self.build and self.version objects, we ended up with those having the value of `{}` (empty dict). In send_notification we expect to have these objects initialized. We should refactor this to only have one point where to catch exceptions and send the notification from there. Related to readthedocs#5672
1 parent 2e797fa commit ace8325

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

readthedocs/projects/tasks.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def run(
412412
self.setup_env.update_build(BUILD_STATE_FINISHED)
413413

414414
# Send notifications for unhandled errors
415-
self.send_notifications()
415+
self.send_notifications(version_pk, build_pk)
416416
return False
417417
else:
418418
# No exceptions in the setup step, catch unhandled errors in the
@@ -440,7 +440,7 @@ def run(
440440
self.build_env.update_build(BUILD_STATE_FINISHED)
441441

442442
# Send notifications for unhandled errors
443-
self.send_notifications()
443+
self.send_notifications(version_pk, build_pk)
444444
return False
445445

446446
return True
@@ -498,7 +498,7 @@ def run_setup(self, record=True):
498498
# triggered before the previous one has finished (e.g. two webhooks,
499499
# one after the other)
500500
if not isinstance(self.setup_env.failure, VersionLockedError):
501-
self.send_notifications()
501+
self.send_notifications(self.version.pk, self.build['id'])
502502

503503
return False
504504

@@ -587,7 +587,7 @@ def run_build(self, docker, record):
587587
log.warning('No build ID, not syncing files')
588588

589589
if self.build_env.failed:
590-
self.send_notifications()
590+
self.send_notifications(self.version.pk, self.build['id'])
591591

592592
build_complete.send(sender=Build, build=self.build_env.build)
593593

@@ -921,9 +921,9 @@ def build_docs_class(self, builder_class):
921921
builder.move()
922922
return success
923923

924-
def send_notifications(self):
924+
def send_notifications(self, version_pk, build_pk):
925925
"""Send notifications on build failure."""
926-
send_notifications.delay(self.version.pk, build_pk=self.build['id'])
926+
send_notifications.delay(version_pk, build_pk=build_pk)
927927

928928
def is_type_sphinx(self):
929929
"""Is documentation type Sphinx."""

0 commit comments

Comments
 (0)