You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "rusackas (via GitHub)" <gi...@apache.org> on 2026/08/06 22:03:42 UTC

[PR] fix(tests): drop removed subtransactions= kwarg from Session.begin() [superset]

rusackas opened a new pull request, #42866:
URL: https://github.com/apache/superset/pull/42866

   ### SUMMARY
   
   `TestDatasource.setUp` (`tests/integration_tests/datasource_tests.py`) explicitly opened a transaction with `db.session.begin(subtransactions=True)` before each test, relying on `tearDown`'s `rollback()` to isolate them.
   
   `subtransactions=` was already deprecated in SQLAlchemy 1.4 and is removed outright in 2.0 (`TypeError: scoped_session.begin() got an unexpected keyword argument 'subtransactions'`). It surfaced while investigating discussion #40273's SQLAlchemy 2.0 bump, but it's a standalone fix independent of that work — `Session` autobegins on first use under both 1.4 and 2.0, so the explicit `begin()` call is unnecessary either way, and `tearDown`'s `rollback()` still correctly discards whatever the test did without it.
   
   ### TESTING INSTRUCTIONS
   
   Ran the full file locally against sqlite (with Redis up for the two cache-dependent tests):
   
   ```
   pytest tests/integration_tests/datasource_tests.py -v
   # 31 passed
   ```
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(tests): drop removed subtransactions= kwarg from Session.begin() [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #42866:
URL: https://github.com/apache/superset/pull/42866#discussion_r3771605690


##########
tests/integration_tests/datasource_tests.py:
##########
@@ -107,9 +107,6 @@ def create_and_cleanup_table(table=None):
 
 
 class TestDatasource(SupersetTestCase):
-    def setUp(self):
-        db.session.begin(subtransactions=True)
-
     def tearDown(self):
         db.session.rollback()

Review Comment:
   Good catch. SQLAlchemy is still pinned to 1.4.54 here, so `subtransactions=True` isn't actually broken yet, and swapping in `begin_nested()` doesn't hold up either without the pysqlite savepoint workaround, which this repo doesn't have. Closing this until the real 2.0 bump can land with a proper isolation fix.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(tests): drop removed subtransactions= kwarg from Session.begin() [superset]

Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #42866:
URL: https://github.com/apache/superset/pull/42866#issuecomment-5209441749

   ### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
   
   
   |  Name | Link |
   |:-:|------------------------|
   |<span aria-hidden="true">🔨</span> Latest commit | 9db868f0afccd5a72a9e5ad9fe3026be8500cf34 |
   |<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6a7504be8a29730008c04eed |
   |<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-42866--superset-docs-preview.netlify.app](https://deploy-preview-42866--superset-docs-preview.netlify.app) |
   |<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br />![QR Code](https://app.netlify.com/qr-code/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1cmwiOiJodHRwczovL2RlcGxveS1wcmV2aWV3LTQyODY2LS1zdXBlcnNldC1kb2NzLXByZXZpZXcubmV0bGlmeS5hcHAifQ.iyeumLZPMWtjd5JnE-Aol_cij1p6XYdXXOHYqv-PGiY)<br /><br />_Use your smartphone camera to open QR code link._</details> |
   |<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#DYtJDoQwDAT_4jMRFsM2_GCekcVAJEiiOCAQmr_jW6mr64GU454KTAAVmKyDXYVnf9VMzD4GZWjxQfFhiljWtsjIKtMeT3ISOUpbvH9Osl4PHbaGRt18hw8ijhZbktf_BQ) |
   ---
   <!-- [superset-docs-preview Preview](https://deploy-preview-42866--superset-docs-preview.netlify.app) -->
   _To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(tests): drop removed subtransactions= kwarg from Session.begin() [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42866:
URL: https://github.com/apache/superset/pull/42866#issuecomment-5274404295

   <!-- Bito Reply -->
   Removing the `setUp` method that initiates a subtransaction means that `db.session.rollback()` in `tearDown` no longer has an active transaction to roll back, allowing commits made during tests to persist. To maintain isolation without the outer transaction, you can explicitly clear the modified state in `tearDown` by deleting the records created during the test or by using a `SAVEPOINT` if your SQLAlchemy setup supports it. Alternatively, you could restore the `setUp` logic but ensure it is compatible with SQLAlchemy 2.0 by using `db.session.begin_nested()` to create a savepoint, which provides a robust isolation boundary for individual tests.
   
   **tests/integration_tests/datasource_tests.py**
   ```
   def setUp(self):
           db.session.begin_nested()
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(tests): drop removed subtransactions= kwarg from Session.begin() [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #42866:
URL: https://github.com/apache/superset/pull/42866#issuecomment-5274732919

   Closing for now. As flagged in the thread above, the fix as written trades a problem that doesn't exist yet (SQLAlchemy is still pinned to 1.4.54, so `subtransactions=True` still works) for a real one: dropping it lets `db.session.commit()` calls inside test-hit views (like `/datasource/save/`) actually persist, so `tearDown`'s `rollback()` can no longer undo them. That needs a proper isolation replacement alongside the actual SQLAlchemy 2.0 bump, not a standalone drive-by.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(tests): drop removed subtransactions= kwarg from Session.begin() [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas closed pull request #42866: fix(tests): drop removed subtransactions= kwarg from Session.begin()
URL: https://github.com/apache/superset/pull/42866


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(tests): drop removed subtransactions= kwarg from Session.begin() [superset]

Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #42866:
URL: https://github.com/apache/superset/pull/42866#discussion_r3771398444


##########
tests/integration_tests/datasource_tests.py:
##########
@@ -107,9 +107,6 @@ def create_and_cleanup_table(table=None):
 
 
 class TestDatasource(SupersetTestCase):
-    def setUp(self):
-        db.session.begin(subtransactions=True)
-
     def tearDown(self):
         db.session.rollback()

Review Comment:
   Removing the outer transaction makes this rollback unable to undo commits made by `test_save` and related tests: `/datasource/save/` calls `db.session.commit()`. That leaks mutations of the shared `birth_names` datasource into later tests, so could this retain an SQLAlchemy-2-compatible isolation boundary or restore the modified state explicitly?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(tests): drop removed subtransactions= kwarg from Session.begin() [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42866:
URL: https://github.com/apache/superset/pull/42866#issuecomment-5209427711

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org