fix: eliminate race condition when creating a review Document (#4876)
This commit is contained in:
parent
0d2e264de4
commit
3d47a9069c
|
@ -711,8 +711,11 @@ def complete_review(request, name, assignment_id=None, acronym=None):
|
||||||
date_today().isoformat(),
|
date_today().isoformat(),
|
||||||
]
|
]
|
||||||
review_name = "-".join(c for c in name_components if c).lower()
|
review_name = "-".join(c for c in name_components if c).lower()
|
||||||
if not Document.objects.filter(name=review_name).exists():
|
review, created = Document.objects.get_or_create(
|
||||||
review = Document.objects.create(name=review_name,type_id='review',group=team)
|
name=review_name,
|
||||||
|
defaults={'type_id': 'review', 'group': team},
|
||||||
|
)
|
||||||
|
if created:
|
||||||
DocAlias.objects.create(name=review_name).docs.add(review)
|
DocAlias.objects.create(name=review_name).docs.add(review)
|
||||||
else:
|
else:
|
||||||
messages.warning(request, message='Attempt to save review failed: review document already exists. This most likely occurred because the review was submitted twice in quick succession. If you intended to submit a new review, rather than update an existing one, things are probably OK. Please verify that the shown review is what you expected.')
|
messages.warning(request, message='Attempt to save review failed: review document already exists. This most likely occurred because the review was submitted twice in quick succession. If you intended to submit a new review, rather than update an existing one, things are probably OK. Please verify that the shown review is what you expected.')
|
||||||
|
|
Loading…
Reference in a new issue