You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jo...@apache.org on 2024/02/16 18:05:28 UTC

(superset) branch master updated: chore(tests): Remove unnecessary explicit Flask-SQLAlchemy session expunges (#27136)

This is an automated email from the ASF dual-hosted git repository.

johnbodley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 8749d9f386 chore(tests): Remove unnecessary explicit Flask-SQLAlchemy session expunges (#27136)
8749d9f386 is described below

commit 8749d9f3865c90e151d0966fc5513ec54a959957
Author: John Bodley <45...@users.noreply.github.com>
AuthorDate: Sat Feb 17 07:05:22 2024 +1300

    chore(tests): Remove unnecessary explicit Flask-SQLAlchemy session expunges (#27136)
---
 tests/integration_tests/base_tests.py                          | 7 ++-----
 tests/integration_tests/core_tests.py                          | 7 +------
 tests/integration_tests/security/guest_token_security_tests.py | 4 ++--
 tests/integration_tests/security_tests.py                      | 6 ++----
 4 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/tests/integration_tests/base_tests.py b/tests/integration_tests/base_tests.py
index 81ad8ccc9f..7b8d8506c3 100644
--- a/tests/integration_tests/base_tests.py
+++ b/tests/integration_tests/base_tests.py
@@ -199,11 +199,8 @@ class SupersetTestCase(TestCase):
     def login(self, username="admin", password="general"):
         return login(self.client, username, password)
 
-    def get_slice(self, slice_name: str, expunge_from_session: bool = True) -> Slice:
-        slc = db.session.query(Slice).filter_by(slice_name=slice_name).one()
-        if expunge_from_session:
-            db.session.expunge_all()
-        return slc
+    def get_slice(self, slice_name: str) -> Slice:
+        return db.session.query(Slice).filter_by(slice_name=slice_name).one()
 
     @staticmethod
     def get_table(
diff --git a/tests/integration_tests/core_tests.py b/tests/integration_tests/core_tests.py
index 4d3c35ec81..573b096fc7 100644
--- a/tests/integration_tests/core_tests.py
+++ b/tests/integration_tests/core_tests.py
@@ -199,7 +199,6 @@ class TestCore(SupersetTestCase):
             url.format(tbl_id, copy_name, "saveas"),
             data={"form_data": json.dumps(form_data)},
         )
-        db.session.expunge_all()
         new_slice_id = resp.json["form_data"]["slice_id"]
         slc = db.session.query(Slice).filter_by(id=new_slice_id).one()
 
@@ -221,7 +220,6 @@ class TestCore(SupersetTestCase):
             url.format(tbl_id, new_slice_name, "overwrite"),
             data={"form_data": json.dumps(form_data)},
         )
-        db.session.expunge_all()
         slc = db.session.query(Slice).filter_by(id=new_slice_id).one()
         self.assertEqual(slc.slice_name, new_slice_name)
         self.assertEqual(slc.viz.form_data, form_data)
@@ -240,10 +238,7 @@ class TestCore(SupersetTestCase):
     def test_slice_data(self):
         # slice data should have some required attributes
         self.login(username="admin")
-        slc = self.get_slice(
-            slice_name="Top 10 Girl Name Share",
-            expunge_from_session=False,
-        )
+        slc = self.get_slice(slice_name="Top 10 Girl Name Share")
         slc_data_attributes = slc.data.keys()
         assert "changed_on" in slc_data_attributes
         assert "modified" in slc_data_attributes
diff --git a/tests/integration_tests/security/guest_token_security_tests.py b/tests/integration_tests/security/guest_token_security_tests.py
index 44a4cdd3ce..a6aed7d6f9 100644
--- a/tests/integration_tests/security/guest_token_security_tests.py
+++ b/tests/integration_tests/security/guest_token_security_tests.py
@@ -257,9 +257,9 @@ class TestGuestUserDatasourceAccess(SupersetTestCase):
                 ],
             }
         )
-        self.chart = self.get_slice("Girls", expunge_from_session=False)
+        self.chart = self.get_slice("Girls")
         self.datasource = self.chart.datasource
-        self.other_chart = self.get_slice("Treemap", expunge_from_session=False)
+        self.other_chart = self.get_slice("Treemap")
         self.other_datasource = self.other_chart.datasource
         self.native_filter_datasource = (
             db.session.query(SqlaTable).filter_by(table_name="dummy_sql_table").first()
diff --git a/tests/integration_tests/security_tests.py b/tests/integration_tests/security_tests.py
index 3ff2f35121..f0b0b5696b 100644
--- a/tests/integration_tests/security_tests.py
+++ b/tests/integration_tests/security_tests.py
@@ -1722,11 +1722,11 @@ class TestSecurityManager(SupersetTestCase):
         mock_is_owner,
     ):
         births = self.get_dash_by_slug("births")
-        girls = self.get_slice("Girls", expunge_from_session=False)
+        girls = self.get_slice("Girls")
         birth_names = girls.datasource
 
         world_health = self.get_dash_by_slug("world_health")
-        treemap = self.get_slice("Treemap", expunge_from_session=False)
+        treemap = self.get_slice("Treemap")
 
         births.json_metadata = json.dumps(
             {
@@ -1872,8 +1872,6 @@ class TestSecurityManager(SupersetTestCase):
                     }
                 )
 
-            db.session.expunge_all()
-
     def test_get_user_roles(self):
         admin = security_manager.find_user("admin")
         with override_user(admin):