Skip to content

test(transaction): add comprehensive transaction mode and advanced feature tests - #20

Merged
vistart merged 3 commits into
release/v1.0.0.dev9from
feature/transaction-expression-support
Apr 8, 2026
Merged

vistart merged 3 commits into
release/v1.0.0.dev9from
feature/transaction-expression-support

Conversation

@vistart

@vistart vistart commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Description

Add comprehensive test coverage for PostgreSQL transaction features, including transaction access modes (READ ONLY/READ WRITE), DEFERRABLE transactions, SET TRANSACTION statement, and SESSION CHARACTERISTICS.

This PR supplements missing test coverage to ensure PostgreSQL backend's transaction capabilities are fully verified.

Type of change

  • test: Adding missing tests or correcting existing tests

Breaking Change

  • Yes
  • No

Applicable rhosocial-activerecord Version Range:

=1.0.0.dev9

Related Repositories/Packages

  • python-activerecord - Core transaction expression support
  • python-activerecord-postgres - PostgreSQL-specific transaction tests

Testing

  • I have added new tests to cover my changes.
  • I have updated existing tests to reflect my changes.
  • All existing tests pass.
  • This change has been tested on PostgreSQL 12+.

Test Plan:

  • pytest tests/rhosocial/activerecord_postgres_test/feature/backend/test_transaction_mode_effect.py
  • pytest tests/rhosocial/activerecord_postgres_test/feature/backend/test_transaction_advanced_features.py
  • pytest tests/rhosocial/activerecord_postgres_test/feature/backend/test_transaction_deferrable.py

Tests added:

  • test_transaction_mode_effect.py (332 lines) - READ ONLY/READ WRITE mode effect tests
  • test_transaction_advanced_features.py (460 lines) - DEFERRABLE, SET TRANSACTION, SESSION CHARACTERISTICS tests
  • Fixed test_transaction_deferrable.py to use public API get_deferred_constraints()

Checklist

  • My code follows the project's code style guidelines.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • My changes generate no new warnings.
  • I have added a Changelog fragment (optional for test-only changes).
  • I have verified that my changes do not introduce SQL injection vulnerabilities.
  • I have checked for potential performance regressions.

Additional Notes

Test Coverage Summary

Feature Sync Tests Async Tests
READ ONLY mode rejects writes ✅ ✅
READ WRITE mode allows writes ✅ ✅
Mode persistence across transactions ✅ ✅
Mode + isolation level combination ✅ ✅
DEFERRABLE SERIALIZABLE transactions ✅ ✅
SET TRANSACTION isolation level ✅ ✅
SET TRANSACTION read only ✅ ✅
SESSION CHARACTERISTICS persistence ✅ ✅
SESSION CHARACTERISTICS reset ✅ ✅
Constraint deferral (fixed) ✅ ✅

All 93 transaction-related tests pass.

…ature tests

- Add test_transaction_mode_effect.py for READ ONLY/READ WRITE mode effects
  - Verify READ ONLY mode rejects INSERT/UPDATE/DELETE operations
  - Verify READ WRITE mode allows all write operations
  - Test mode persistence across transactions
  - Test mode combined with isolation level
  - Include both sync and async test coverage

- Add test_transaction_advanced_features.py for advanced PostgreSQL features
  - Test DEFERRABLE transaction behavior with SERIALIZABLE isolation
  - Test SET TRANSACTION statement for isolation level and access mode
  - Test SESSION CHARACTERISTICS persistence and reset
  - Include async test counterparts

- Fix test_transaction_deferrable.py to use public API
  - Replace _deferred_constraints private attribute access with get_deferred_constraints()

All tests verify PostgreSQL transaction features work correctly with the
transaction manager and expression system.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov

codecov Bot commented Apr 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.89%. Comparing base (87eea51) to head (c067f9f).
⚠️ Report is 1 commits behind head on release/v1.0.0.dev9.

Additional details and impacted files
@@                   Coverage Diff                   @@
##           release/v1.0.0.dev9      #20      +/-   ##
=======================================================
+ Coverage                72.56%   72.89%   +0.32%     
=======================================================
  Files                      112      112              
  Lines                     6008     6006       -2     
  Branches                   991      991              
=======================================================
+ Hits                      4360     4378      +18     
+ Misses                    1338     1322      -16     
+ Partials                   310      306       -4     
Flag Coverage Δ
postgres-18 72.89% <ø> (+0.32%) ⬆️
python-3.14 72.89% <ø> (+0.32%) ⬆️
unittests 72.89% <ø> (+0.32%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

PostgreSQL does not require explicit isolation level in BEGIN statement.
When isolation_level is None (not explicitly set), BEGIN should not
include ISOLATION LEVEL clause, allowing SESSION CHARACTERISTICS to
take effect.

Changes:
- Remove default isolation_level initialization in PostgresTransactionManager
- Remove default isolation_level initialization in AsyncPostgresTransactionManager
- Update test_session_characteristics_with_isolation_level to verify
  that SESSION CHARACTERISTICS work when isolation_level is None
- Add async counterpart test for sync/async parity

This ensures:
1. BEGIN without explicit isolation level respects SESSION CHARACTERISTICS
2. Users can still set explicit isolation_level to override session defaults
3. Synchronous and asynchronous behaviors are equivalent

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vistart vistart self-assigned this Apr 8, 2026
@vistart vistart added the feature label Apr 8, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Apr 8, 2026

Copy link
Copy Markdown

@vistart
vistart merged commit c0672f5 into release/v1.0.0.dev9 Apr 8, 2026
14 checks passed
@vistart vistart mentioned this pull request Apr 8, 2026
3 of 11 tasks
vistart added a commit that referenced this pull request Apr 8, 2026
…ature tests (#20)

* test(transaction): add comprehensive transaction mode and advanced feature tests

- Add test_transaction_mode_effect.py for READ ONLY/READ WRITE mode effects
  - Verify READ ONLY mode rejects INSERT/UPDATE/DELETE operations
  - Verify READ WRITE mode allows all write operations
  - Test mode persistence across transactions
  - Test mode combined with isolation level
  - Include both sync and async test coverage

- Add test_transaction_advanced_features.py for advanced PostgreSQL features
  - Test DEFERRABLE transaction behavior with SERIALIZABLE isolation
  - Test SET TRANSACTION statement for isolation level and access mode
  - Test SESSION CHARACTERISTICS persistence and reset
  - Include async test counterparts

- Fix test_transaction_deferrable.py to use public API
  - Replace _deferred_constraints private attribute access with get_deferred_constraints()

All tests verify PostgreSQL transaction features work correctly with the
transaction manager and expression system.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(transaction): respect PostgreSQL optional syntax for BEGIN statement

PostgreSQL does not require explicit isolation level in BEGIN statement.
When isolation_level is None (not explicitly set), BEGIN should not
include ISOLATION LEVEL clause, allowing SESSION CHARACTERISTICS to
take effect.

Changes:
- Remove default isolation_level initialization in PostgresTransactionManager
- Remove default isolation_level initialization in AsyncPostgresTransactionManager
- Update test_session_characteristics_with_isolation_level to verify
  that SESSION CHARACTERISTICS work when isolation_level is None
- Add async counterpart test for sync/async parity

This ensures:
1. BEGIN without explicit isolation level respects SESSION CHARACTERISTICS
2. Users can still set explicit isolation_level to override session defaults
3. Synchronous and asynchronous behaviors are equivalent

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: add changelog fragment for PR #20

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@vistart
vistart deleted the feature/transaction-expression-support branch April 9, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant