Skip to content

Commit d94e7db

Browse files
committed
add logging, fix small issues
1 parent 9bf6d24 commit d94e7db

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

casbin_adapter/enforcer.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from django.conf import settings
23
from django.db import connection
34
from django.db.utils import OperationalError, ProgrammingError
@@ -7,6 +8,8 @@
78
from .adapter import Adapter
89
from .utils import import_class
910

11+
logger = logging.getLogger(__name__)
12+
1013

1114

1215
class ProxyEnforcer(Enforcer):
@@ -15,18 +18,22 @@ class ProxyEnforcer(Enforcer):
1518
def __init__(self, *args, **kwargs):
1619
if self._initialized:
1720
super().__init__(*args, **kwargs)
21+
else:
22+
logger.info('Deferring casbin enforcer initialisation until django is ready')
1823

1924
def _load(self):
2025
if self._initialized == False:
26+
logger.info('Performing deferred casbin enforcer initialisation')
2127
self._initialized = True
2228
model = getattr(settings, 'CASBIN_MODEL')
2329
enable_log = getattr(settings, 'CASBIN_LOG_ENABLED', False)
2430
adapter_loc = getattr(settings, 'CASBIN_ADAPTER', 'casbin_adapter.adapter.Adapter')
2531
adapter_args = getattr(settings, 'CASBIN_ADAPTER_ARGS', tuple())
2632
Adapter = import_class(adapter_loc)
27-
adapter = adapter_class(*adapter_args)
33+
adapter = Adapter(*adapter_args)
2834

2935
super().__init__(model, adapter, enable_log)
36+
logger.debug('Casbin enforcer initialised')
3037

3138
watcher = getattr(settings, 'CASBIN_WATCHER', None)
3239
if watcher:

casbin_adapter/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def import_class(name):
44
"""Import class from string
55
e.g. `package.module.ClassToImport` returns the `ClasToImport` class"""
66
components = name.split('.')
7-
module_name = components[:-1].join('.')
7+
module_name = '.'.join(components[:-1])
88
class_name = components[-1]
99
module = importlib.import_module(module_name)
1010
class_ = getattr(module, class_name)

0 commit comments

Comments
 (0)