Skip to content

Commit

Permalink
add duplicate view name entry error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
eschutho committed Dec 7, 2024
1 parent ea13294 commit fc45193
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
20 changes: 18 additions & 2 deletions superset/migrations/shared/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,15 @@ def upgrade_schema_perms(
.filter_by(name=current_perm)
.one_or_none()
):
existing_pvm.name = new_perm
# check that new_perm does not exist
if session.query(ViewMenu).filter_by(name=new_perm).one_or_none():
logger.warning(
"New permission %s already exists. Removing old one",
new_perm,
)
session.delete(existing_pvm)
else:
existing_pvm.name = new_perm
elif new_perm:
# new schema discovered, need to create a new permission
perms[new_perm] = ("schema_access",)
Expand Down Expand Up @@ -683,7 +691,15 @@ def downgrade_schema_perms(
None,
schema,
)
pvms_to_rename.append((pvm, new_name))
# check to see if the new name already exists
if session.query(ViewMenu).filter_by(name=new_name).one_or_none():
logger.warning(
"New permission %s already exists. Deleting old one",
new_name,
)
pvms_to_delete.append(pvm)
else:
pvms_to_rename.append((pvm, new_name))
else:
# non-default catalog, delete schema perm
pvms_to_delete.append(pvm)
Expand Down
5 changes: 5 additions & 0 deletions superset/migrations/shared/security_converge.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ def _add_view_menu(session: Session, view_name: str) -> ViewMenu:
"""
Check and add the new view menu
"""
# Check if the object is already in the session
for obj in session.identity_map.values():
if isinstance(obj, ViewMenu) and obj.name == view_name:
return obj

new_view = session.query(ViewMenu).filter(ViewMenu.name == view_name).one_or_none()
if not new_view:
new_view = ViewMenu(name=view_name)
Expand Down

0 comments on commit fc45193

Please sign in to comment.