Skip to content

Defer change request publishing side effects until transaction commit #8299

Description

@coderabbitai

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions