File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change 1
- from django .conf import settings
1
+ import logging
2
+
2
3
from casbin import persist
4
+ from django .db .utils import OperationalError , ProgrammingError
3
5
4
6
from .models import CasbinRule
5
7
8
+ logger = logging .getLogger (__name__ )
9
+
6
10
7
11
class Adapter (persist .Adapter ):
8
12
"""the interface for Casbin adapters."""
9
13
10
14
def load_policy (self , model ):
11
15
"""loads all policy rules from the storage."""
12
- lines = CasbinRule .objects .all ()
16
+ try :
17
+ lines = CasbinRule .objects .all ()
13
18
14
- for line in lines :
15
- persist .load_policy_line (str (line ), model )
19
+ for line in lines :
20
+ persist .load_policy_line (str (line ), model )
21
+ except (OperationalError , ProgrammingError ) as error :
22
+ logger .warning ("Could not load policy from database: {}" .format (error ))
16
23
17
24
def _create_policy_line (self , ptype , rule ):
18
25
line = CasbinRule (ptype = ptype )
You can’t perform that action at this time.
0 commit comments