Use document_db.save() instead of PersistanceClass.save().
Using persistance class instead of the document class means an index is
not created and this can cause various issues.
from __future__ import absolute_import
from mongoengine import NotUniqueError
+from st2common import log as logging
from st2common.rbac.types import SystemRole
-from st2common.persistence.rbac import Role
from st2common.models.db.rbac import RoleDB
from st2common.exceptions.db import StackStormDBObjectConflictError
+LOG = logging.getLogger(__name__)
+
__all__ = [
'run_all',
@@ -38,11 +40,15 @@ def insert_system_roles():
"""
system_roles = SystemRole.get_valid_values()
+ LOG.debug('Inserting system roles (%s)' % (str(system_roles)))
+
for role_name in system_roles:
description = role_name
role_db = RoleDB(name=role_name, description=description, system=True)
try:
- Role.insert(role_db, log_not_unique_error_as_debug=True)
- except (StackStormDBObjectConflictError, NotUniqueError):
+ role_db.save()
+ #Role.insert(role_db, log_not_unique_error_as_debug=True)
+ except (StackStormDBObjectConflictError, NotUniqueError) as e:
+ # Role already exists error is not fatal
pass
