Commit 6fa12885 by Diana Huang

Handle IntegrityError according to 1.8 conventions.

parent b8307ca9
......@@ -115,6 +115,7 @@ def on_start(submission_uuid):
"""
try:
with transaction.atomic():
submission = sub_api.get_submission_and_student(submission_uuid)
workflow, __ = PeerWorkflow.objects.get_or_create(
student_id=submission['student_item']['student_id'],
......@@ -721,6 +722,7 @@ def create_peer_workflow(submission_uuid):
"""
try:
with transaction.atomic():
submission = sub_api.get_submission_and_student(submission_uuid)
workflow, __ = PeerWorkflow.objects.get_or_create(
student_id=submission['student_item']['student_id'],
......
......@@ -2,7 +2,7 @@
Public interface for staff grading, used by students/course staff.
"""
import logging
from django.db import DatabaseError, IntegrityError, transaction
from django.db import DatabaseError, transaction
from django.utils.timezone import now
from dogapi import dog_stats_api
......
"""
Django models specific to the student training assessment type.
"""
from django.db import models, IntegrityError
from django.db import models, transaction, IntegrityError
from django.utils import timezone
from submissions import api as sub_api
from .training import TrainingExample
......@@ -137,6 +137,7 @@ class StudentTrainingWorkflow(models.Model):
next_example = available_examples[0]
try:
with transaction.atomic():
StudentTrainingWorkflowItem.objects.create(
workflow=self,
order_num=order_num,
......
......@@ -181,6 +181,7 @@ def deserialize_training_examples(examples, rubric_dict):
example = TrainingExample.objects.get(content_hash=content_hash)
except TrainingExample.DoesNotExist:
try:
with transaction.atomic():
example = TrainingExample.create_example(
example_dict['answer'], example_dict['options_selected'], rubric
)
......
......@@ -103,7 +103,7 @@ class StudentTrainingAssessmentTest(CacheResetTest):
# This will need to create the student training workflow and the first item
# NOTE: we *could* cache the rubric model to reduce the number of queries here,
# but we're selecting it by content hash, which is indexed and should be plenty fast.
with self.assertNumQueries(6):
with self.assertNumQueries(8):
training_api.get_training_example(self.submission_uuid, RUBRIC, EXAMPLES)
# Without assessing the first training example, try to retrieve a training example.
......@@ -117,7 +117,7 @@ class StudentTrainingAssessmentTest(CacheResetTest):
# Retrieve the next training example, which requires us to create
# a new workflow item (but not a new workflow).
with self.assertNumQueries(6):
with self.assertNumQueries(8):
training_api.get_training_example(self.submission_uuid, RUBRIC, EXAMPLES)
def test_submitter_is_finished_num_queries(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment