Skip to content

chore(django-spanner): disable savepoints and remove can_rollback_tests#16866

Merged
sinhasubham merged 1 commit intomainfrom
django-savepoints-fix
Apr 29, 2026
Merged

chore(django-spanner): disable savepoints and remove can_rollback_tests#16866
sinhasubham merged 1 commit intomainfrom
django-savepoints-fix

Conversation

@sinhasubham
Copy link
Copy Markdown
Contributor

@sinhasubham sinhasubham commented Apr 29, 2026

  • Set uses_savepoints = False in features.py to prevent silent rollback failures in production, as Cloud Spanner does not support savepoints natively.

Additionally, 9 tests (primarily from sessions_tests) were added to the emulator skip list. These tests are designed to simulate expected failures within a transaction and rely on savepoints to recover and continue execution. Because we have disabled savepoints (uses_savepoints = False) for production safety, and Cloud Spanner breaks the entire transaction upon encountering any error, these tests are unable to recover and fail with TransactionManagementError. They have been skipped on the emulator as they are fundamentally incompatible with Spanner's transaction model without native savepoint support.

Fixes #16839

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the DatabaseFeatures class in django_spanner by setting uses_savepoints to False and removing the can_rollback_tests attribute. The reviewer identified that removing can_rollback_tests is a breaking change for supported Django versions (4.2, 5.0, and 5.1), as it would cause the test suite to incorrectly attempt transaction-based isolation instead of the required flush method. A suggestion was provided to retain the attribute and add explanatory comments to both flags for better compatibility and clarity.

Comment thread packages/django-google-spanner/django_spanner/features.py Outdated
@sinhasubham sinhasubham force-pushed the django-savepoints-fix branch from 04e6af6 to adf7b2f Compare April 29, 2026 12:47
@sinhasubham sinhasubham changed the title chore(django-spanner): disable savepoints and remove can_rollack_tests chore(django-spanner): disable savepoints and remove can_rollback_tests Apr 29, 2026
@sinhasubham sinhasubham force-pushed the django-savepoints-fix branch from adf7b2f to 9e838d0 Compare April 29, 2026 13:38
Comment on lines +277 to +285
"fixtures_model_package.tests.FixtureTestCase.test_loaddata",
"sessions_tests.tests.CacheDBSessionTests.test_session_asave_does_not_resurrect_session_logged_out_in_other_context",
"sessions_tests.tests.CacheDBSessionTests.test_session_save_does_not_resurrect_session_logged_out_in_other_context",
"sessions_tests.tests.CacheDBSessionWithTimeZoneTests.test_session_asave_does_not_resurrect_session_logged_out_in_other_context",
"sessions_tests.tests.CacheDBSessionWithTimeZoneTests.test_session_save_does_not_resurrect_session_logged_out_in_other_context",
"sessions_tests.tests.CustomDatabaseSessionTests.test_session_asave_does_not_resurrect_session_logged_out_in_other_context",
"sessions_tests.tests.CustomDatabaseSessionTests.test_session_save_does_not_resurrect_session_logged_out_in_other_context",
"sessions_tests.tests.DatabaseSessionTests.test_session_asave_does_not_resurrect_session_logged_out_in_other_context",
"sessions_tests.tests.DatabaseSessionTests.test_session_save_does_not_resurrect_session_logged_out_in_other_context",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are designed to simulate expected failures within a transaction and rely on savepoints to recover and continue execution. Because we have disabled savepoints (uses_savepoints = False) for production safety, and Cloud Spanner breaks the entire transaction upon encountering any error, these tests are unable to recover and fail with TransactionManagementError. They have been skipped on the emulator as they are fundamentally incompatible with Spanner's transaction model without native savepoint support.

These were passing previously because when uses_savepoints was set to True, our adapter emulated savepoints as dummy no-op statements. This allowed the test flow to proceed without Django immediately detecting that the transaction was broken.

@sinhasubham sinhasubham marked this pull request as ready for review April 29, 2026 14:09
@sinhasubham sinhasubham requested a review from a team as a code owner April 29, 2026 14:10
@parthea
Copy link
Copy Markdown
Contributor

parthea commented Apr 29, 2026

Switching to draft until presubmits are green

Fixed as of 72f0438

@parthea parthea marked this pull request as draft April 29, 2026 14:56
@sinhasubham sinhasubham force-pushed the django-savepoints-fix branch from 9e838d0 to 72f0438 Compare April 29, 2026 15:29
@parthea parthea marked this pull request as ready for review April 29, 2026 15:36
supports_subqueries_in_group_by = False
uses_savepoints = True
uses_savepoints = False # Spanner does not support savepoints.
can_rollback_tests = False # Spanner savepoints are no-ops; rely on flush.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this value still correct? The comment is at least now outdated, as we explicitly turn off savepoints

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this line if we plan to stop supporting versions 5.0/5.1. This is dead code for Django >=5.2.

@sinhasubham sinhasubham merged commit 927f1fb into main Apr 29, 2026
47 checks passed
@sinhasubham sinhasubham deleted the django-savepoints-fix branch April 29, 2026 16:48
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.

django tests may still be flaky

3 participants