Skip to content

Commit a35aa67

Browse files
chore: clarify transaction-related comments (ietf-tools#8180)
1 parent 8c787b5 commit a35aa67

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

ietf/community/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def notify_events(sender, instance, **kwargs):
117117
# start a Celery task during tests. To prevent this, don't queue a celery task if we're running
118118
# tests.
119119
if settings.SERVER_MODE != "test":
120-
# Wrap in on_commit so the delayed task cannot start until the view is done with the DB
120+
# Wrap in on_commit in case a transaction is open
121121
transaction.on_commit(
122122
lambda: notify_event_to_subscribers_task.delay(event_id=instance.pk)
123123
)

ietf/submit/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,8 +2334,8 @@ def test_cancel_preapproval(self):
23342334
self.assertEqual(len(Preapproval.objects.filter(name=preapproval.name)), 0)
23352335

23362336

2337-
# Transaction.on_commit() requires use of TransactionTestCase, but that has a performance penalty. Replace it
2338-
# with a no-op for testing purposes.
2337+
# Transaction.on_commit() interacts badly with TestCase's transaction behavior. Replace it
2338+
# with a pass-through for testing purposes.
23392339
@mock.patch.object(transaction, 'on_commit', lambda x: x())
23402340
@override_settings(IDTRACKER_BASE_URL='https://datatracker.example.com')
23412341
class ApiSubmissionTests(BaseSubmitTestCase):

ietf/submit/views.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ def upload_submission(request):
9090
clear_existing_files(form)
9191
save_files(form)
9292
create_submission_event(request, submission, desc="Uploaded submission")
93-
# Wrap in on_commit so the delayed task cannot start until the view is done with the DB
93+
# Wrap in on_commit in case a transaction is open
94+
# (As of 2024-11-08, this only runs in a transaction during tests)
9495
transaction.on_commit(
9596
lambda: process_uploaded_submission_task.delay(submission.pk)
9697
)
@@ -166,7 +167,8 @@ def err(code, error, messages=None):
166167
save_files(form)
167168
create_submission_event(request, submission, desc="Uploaded submission through API")
168169

169-
# Wrap in on_commit so the delayed task cannot start until the view is done with the DB
170+
# Wrap in on_commit in case a transaction is open
171+
# (As of 2024-11-08, this only runs in a transaction during tests)
170172
transaction.on_commit(
171173
lambda: process_and_accept_uploaded_submission_task.delay(submission.pk)
172174
)

ietf/sync/views.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,29 @@ def notify(request, org, notification):
8080
if request.method == "POST":
8181
if notification == "index":
8282
log("Queuing RFC Editor index sync from notify view POST")
83-
# Wrap in on_commit so the delayed task cannot start until the view is done with the DB
83+
# Wrap in on_commit in case a transaction is open
84+
# (As of 2024-11-08, this only runs in a transaction during tests)
8485
transaction.on_commit(
8586
lambda: tasks.rfc_editor_index_update_task.delay()
8687
)
8788
elif notification == "queue":
8889
log("Queuing RFC Editor queue sync from notify view POST")
89-
# Wrap in on_commit so the delayed task cannot start until the view is done with the DB
90+
# Wrap in on_commit in case a transaction is open
91+
# (As of 2024-11-08, this only runs in a transaction during tests)
9092
transaction.on_commit(
9193
lambda: tasks.rfc_editor_queue_updates_task.delay()
9294
)
9395
elif notification == "changes":
9496
log("Queuing IANA changes sync from notify view POST")
95-
# Wrap in on_commit so the delayed task cannot start until the view is done with the DB
97+
# Wrap in on_commit in case a transaction is open
98+
# (As of 2024-11-08, this only runs in a transaction during tests)
9699
transaction.on_commit(
97100
lambda: tasks.iana_changes_update_task.delay()
98101
)
99102
elif notification == "protocols":
100103
log("Queuing IANA protocols sync from notify view POST")
101-
# Wrap in on_commit so the delayed task cannot start until the view is done with the DB
104+
# Wrap in on_commit in case a transaction is open
105+
# (As of 2024-11-08, this only runs in a transaction during tests)
102106
transaction.on_commit(
103107
lambda: tasks.iana_protocols_update_task.delay()
104108
)

0 commit comments

Comments
 (0)