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: [cli] permission cleanup on 'superset init' (#4241)
Date Sun, 04 Feb 2018 04:12:48 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 a616bf4  [cli] permission cleanup on 'superset init' (#4241)
a616bf4 is described below

commit a616bf4082337ee73f6ed941436053eaafda9a22
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Sat Feb 3 20:12:45 2018 -0800

    [cli] permission cleanup on 'superset init' (#4241)
    
    * [cli] permission cleanup on 'superset init'
    
    FAB sometimes creates NULL/None permissions in the database,
    presumably a race condition when multiple gunicorn workers start at the
    same time, and those create issues raising "AttributeError: 'NoneType'
    object has no attribute 'name'"
    
    * Linting
---
 superset/security.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/superset/security.py b/superset/security.py
index a2e0d5a..fa056c3 100644
--- a/superset/security.py
+++ b/superset/security.py
@@ -7,6 +7,7 @@ from __future__ import unicode_literals
 import logging
 
 from flask_appbuilder.security.sqla import models as ab_models
+from sqlalchemy import or_
 
 from superset import conf, db, sm
 from superset.connectors.connector_registry import ConnectorRegistry
@@ -210,6 +211,23 @@ def create_missing_perms():
             merge_pv('metric_access', metric.perm)
 
 
+def clean_perms():
+    """FAB leaves faulty permissions that need to be cleaned up"""
+    logging.info('Cleaning faulty perms')
+    sesh = sm.get_session()
+    pvms = (
+        sesh.query(ab_models.PermissionView)
+        .filter(or_(
+            ab_models.PermissionView.permission == None,  # NOQA
+            ab_models.PermissionView.view_menu == None,  # NOQA
+        ))
+    )
+    deleted_count = pvms.delete()
+    sesh.commit()
+    if deleted_count:
+        logging.info('Deleted {} faulty permissions'.format(deleted_count))
+
+
 def sync_role_definitions():
     """Inits the Superset application with security roles and such"""
     logging.info('Syncing role definition')
@@ -231,3 +249,4 @@ def sync_role_definitions():
 
     # commit role and view menu updates
     sm.get_session.commit()
+    clean_perms()

-- 
To stop receiving notification emails like this one, please contact
maximebeauchemin@apache.org.

Mime
View raw message