superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: [bugfix] SQLA instance has been deleted (#3159)
Date Wed, 19 Jul 2017 08:35:03 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new c34df3e  [bugfix] SQLA instance has been deleted (#3159)
c34df3e is described below

commit c34df3eea40eacc59097fba14fab395bb0cd5989
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Wed Jul 19 01:35:00 2017 -0700

    [bugfix] SQLA instance has been deleted (#3159)
    
    Related Msg:
    sqlalchemy.orm.exc.ObjectDeletedError: Instance '<PermissionView at
    0x7f10306b0e90>' has been deleted, or its row is otherwise not present.
---
 superset/security.py | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/superset/security.py b/superset/security.py
index 9a01d6b..0128911 100644
--- a/superset/security.py
+++ b/superset/security.py
@@ -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()
 
@@ -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()
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <commits@superset.apache.org>'].

Mime
View raw message