This is an automated email from the ASF dual-hosted git repository.
beto 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 a56f656a83 fix: small fixes to the catalog migration (#29579)
a56f656a83 is described below
commit a56f656a832978d4ac80605aa0683c18380f8d13
Author: Beto Dealmeida <[email protected]>
AuthorDate: Fri Jul 12 20:49:30 2024 -0400
fix: small fixes to the catalog migration (#29579)
---
superset/migrations/shared/catalogs.py | 9 +++++++--
tests/unit_tests/security/manager_test.py | 4 ++--
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/superset/migrations/shared/catalogs.py
b/superset/migrations/shared/catalogs.py
index b4c8658cbe..27952371bd 100644
--- a/superset/migrations/shared/catalogs.py
+++ b/superset/migrations/shared/catalogs.py
@@ -102,7 +102,8 @@ WHERE
ap.name = 'schema_access';
"""
# [PostgreSQL].[postgres].[public] => public
- return sorted({row[0].split(".")[-1][1:-1] for row in op.execute(query)})
+ conn = op.get_bind()
+ return sorted({row[0].split(".")[-1][1:-1] for row in conn.execute(query)})
def upgrade_catalog_perms(engines: set[str] | None = None) -> None:
@@ -267,8 +268,12 @@ def downgrade_schema_perms(database: Database, catalog:
str, session: Session) -
)
existing_pvm =
session.query(ViewMenu).filter_by(name=perm).one_or_none()
if existing_pvm:
- existing_pvm.name = security_manager.get_schema_perm(
+ new_perm = security_manager.get_schema_perm(
database.database_name,
None,
schema,
)
+ if pvm :=
session.query(ViewMenu).filter_by(name=new_perm).one_or_none():
+ session.delete(pvm)
+ session.flush()
+ existing_pvm.name = new_perm
diff --git a/tests/unit_tests/security/manager_test.py
b/tests/unit_tests/security/manager_test.py
index 2d3e7250be..a83e415529 100644
--- a/tests/unit_tests/security/manager_test.py
+++ b/tests/unit_tests/security/manager_test.py
@@ -726,7 +726,7 @@ def test_raise_for_access_catalog(
mocker.patch.object(
sm,
"get_catalog_perm",
- return_value="[PostgreSQL].[db1].[public]",
+ return_value="[PostgreSQL].[db1]",
)
mocker.patch.object(sm, "is_guest_user", return_value=False)
SqlaTable = mocker.patch("superset.connectors.sqla.models.SqlaTable")
@@ -741,7 +741,7 @@ def test_raise_for_access_catalog(
can_access = mocker.patch.object(sm, "can_access", return_value=True)
sm.raise_for_access(query=query)
- can_access.assert_called_with("catalog_access",
"[PostgreSQL].[db1].[public]")
+ can_access.assert_called_with("catalog_access", "[PostgreSQL].[db1]")
mocker.patch.object(sm, "can_access", return_value=False)
with pytest.raises(SupersetSecurityException) as excinfo: