Skip to content

Conversation

@barnabasJ
Copy link
Contributor

Summary

Add comprehensive tests for after_transaction hooks in bulk operations with PostgreSQL.

These tests verify the fix in ash-project/ash#2532, which ensures after_transaction hooks are called when
batch transactions fail during bulk_create, bulk_update, and bulk_destroy operations.

Test Coverage

  • bulk_create: Tests transaction: :batch and transaction: :all modes
  • bulk_update: Tests :stream, :atomic, and :atomic_batches strategies
  • bulk_destroy: Tests :stream, :atomic, and :atomic_batches strategies

Each test file verifies:

  • Hooks run outside batch transactions (no warning emitted)
  • Partial failures commit successful batches correctly
  • after_transaction receives proper success/error status
  • Rollback behavior works as expected

Dependencies

Requires ash-project/ash#2532

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

Enable bulk_actions_default_to_errors? globally for consistent
bulk operation behavior. Add disable_async? in test env to
simplify test assertions by running hooks synchronously.
Create test resource with change modules exercising various
after_action and after_transaction hook scenarios:

- Simple success hooks that send messages for verification
- Conditional failures based on record content
- Hooks that return errors to trigger rollbacks
- Atomic-compatible changes for all bulk strategies

Includes actions for create, update, and destroy operations.
Generate migrations for the AfterTransactionPost test resource.
Creates table with id, title, and status attributes.
Test after_transaction hook behavior in bulk_create operations
with transaction: :batch and transaction: :all modes.

Verifies hooks handle empty results, capture errors correctly,
and that transaction semantics work as expected.
Test after_transaction hook behavior in bulk_update operations
across :stream, :atomic, and :atomic_batches strategies.

Verifies hooks run outside batch transactions, partial failures
commit successful batches, and atomic strategies work correctly.
Test after_transaction hook behavior in bulk_destroy operations
across :stream, :atomic, and :atomic_batches strategies.

Completes test coverage for after_transaction hooks across
all three bulk operation types.
@barnabasJ barnabasJ self-assigned this Jan 26, 2026
@zachdaniel zachdaniel merged commit 70f6905 into main Jan 29, 2026
61 of 67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants