Skip to content

Commit

Permalink
[bugfix] SQLA instance has been deleted (#3159)
Browse files Browse the repository at this point in the history
Related Msg:
sqlalchemy.orm.exc.ObjectDeletedError: Instance '<PermissionView at
0x7f10306b0e90>' has been deleted, or its row is otherwise not present.
  • Loading branch information
mistercrunch authored Jul 19, 2017
1 parent 56bcbb0 commit c34df3e
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions superset/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ def is_granter_pvm(pvm):
'can_approve'}


def set_role(role_name, pvms, pvm_check):
def set_role(role_name, pvm_check):
logging.info("Syncing {} perms".format(role_name))
sesh = sm.get_session()
pvms = sesh.query(ab_models.PermissionView).all()
pvms = [p for p in pvms if p.permission and p.view_menu]
role = sm.add_role(role_name)
role_pvms = [p for p in pvms if pvm_check(p)]
role.permissions = role_pvms
sesh = sm.get_session()
sesh.merge(role)
sesh.commit()

Expand Down Expand Up @@ -200,24 +202,15 @@ def sync_role_definitions():
get_or_create_main_db()
create_custom_permissions()

pvms = db.session.query(ab_models.PermissionView).all()
pvms = [p for p in pvms if p.permission and p.view_menu]

# cleanup
pvms_to_delete = [p for p in pvms if not (p.permission and p.view_menu)]

for pvm_to_delete in pvms_to_delete:
sm.get_session.delete(pvm_to_delete)

# Creating default roles
set_role('Admin', pvms, is_admin_pvm)
set_role('Alpha', pvms, is_alpha_pvm)
set_role('Gamma', pvms, is_gamma_pvm)
set_role('granter', pvms, is_granter_pvm)
set_role('sql_lab', pvms, is_sql_lab_pvm)
set_role('Admin', is_admin_pvm)
set_role('Alpha', is_alpha_pvm)
set_role('Gamma', is_gamma_pvm)
set_role('granter', is_granter_pvm)
set_role('sql_lab', is_sql_lab_pvm)

if conf.get('PUBLIC_ROLE_LIKE_GAMMA', False):
set_role('Public', pvms, is_gamma_pvm)
set_role('Public', is_gamma_pvm)

create_missing_perms()

Expand Down

0 comments on commit c34df3e

Please sign in to comment.