Exception handling for data outputs (#12797)

This commit is contained in:
Oliver
2026-09-06 21:36:01 +10:00
committed by GitHub
parent 1218af7366
commit 4a0e28510f
+28
View File
@@ -32,10 +32,24 @@ def print_reports(
try:
template = ReportTemplate.objects.get(pk=template_id)
output = DataOutput.objects.get(pk=output_id)
except DataOutput.DoesNotExist:
# The DataOutput may have already been consumed and deleted by the time
# this task runs (e.g. if the background worker redelivered the task)
logger.info(
'DataOutput %s no longer exists - skipping print_reports task', output_id
)
return
except Exception:
log_error('report.tasks.print_reports')
return
if output.complete:
# This task has already been processed (e.g. a redelivered/duplicate task) - skip it
logger.info(
'DataOutput %s is already complete - skipping print_reports task', output_id
)
return
# Fetch user information
user = None
@@ -86,10 +100,24 @@ def print_labels(
try:
template = LabelTemplate.objects.get(pk=template_id)
output = DataOutput.objects.get(pk=output_id)
except DataOutput.DoesNotExist:
# The DataOutput may have already been consumed and deleted by the time
# this task runs (e.g. if the background worker redelivered the task)
logger.info(
'DataOutput %s no longer exists - skipping print_labels task', output_id
)
return
except Exception:
log_error('report.tasks.print_labels')
return
if output.complete:
# This task has already been processed (e.g. a redelivered/duplicate task) - skip it
logger.info(
'DataOutput %s is already complete - skipping print_labels task', output_id
)
return
# Fetch user information
user = None