Summary
Defer external side effects from change request publishing until the enclosing database transaction commits successfully.
Rationale
ChangeRequestCommitService.commit() now runs in transaction.atomic. _publish_environment_feature_versions() dispatches Celery tasks and sends environment_feature_version_published before this transaction commits. If a later operation fails, for example when _publish_segments() rejects a system segment, the database transaction rolls back but queued tasks and signal-receiver side effects can still run against data that was not committed.
Affected area
api/core/workflows_services.py
ChangeRequestCommitService._publish_environment_feature_versions
Required changes
Register trigger_update_version_webhooks.delay(...), rebuild_environment_document.delay(...), and environment_feature_version_published.send(...) through transaction.on_commit(). Bind each loop value in its callback so callbacks use the correct environment feature version and scheduled timestamp.
Acceptance criteria
- No Celery task is dispatched when
ChangeRequestCommitService.commit() rolls back.
- No
environment_feature_version_published receiver runs when ChangeRequestCommitService.commit() rolls back.
- The existing side effects run after a successful transaction commit.
- Tests cover both rollback and successful commit behaviour.
Backlinks
Summary
Defer external side effects from change request publishing until the enclosing database transaction commits successfully.
Rationale
ChangeRequestCommitService.commit()now runs intransaction.atomic._publish_environment_feature_versions()dispatches Celery tasks and sendsenvironment_feature_version_publishedbefore this transaction commits. If a later operation fails, for example when_publish_segments()rejects a system segment, the database transaction rolls back but queued tasks and signal-receiver side effects can still run against data that was not committed.Affected area
api/core/workflows_services.pyChangeRequestCommitService._publish_environment_feature_versionsRequired changes
Register
trigger_update_version_webhooks.delay(...),rebuild_environment_document.delay(...), andenvironment_feature_version_published.send(...)throughtransaction.on_commit(). Bind each loop value in its callback so callbacks use the correct environment feature version and scheduled timestamp.Acceptance criteria
ChangeRequestCommitService.commit()rolls back.environment_feature_version_publishedreceiver runs whenChangeRequestCommitService.commit()rolls back.Backlinks