Skip to content

Commit

Permalink
fix: small fixes to the catalog migration (apache#29579)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Jul 13, 2024
1 parent fa095a9 commit a56f656
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions superset/migrations/shared/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def get_schemas(database_name: str) -> list[str]:
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:
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/unit_tests/security/manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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:
Expand Down

0 comments on commit a56f656

Please sign in to comment.