You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@casbin.apache.org by hs...@apache.org on 2026/08/06 06:23:20 UTC

(casbin-python-django-orm-adapter) branch master updated: fix: lazy init and infinite recursion fixes (#5)

This is an automated email from the ASF dual-hosted git repository.

hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-python-django-orm-adapter.git


The following commit(s) were added to refs/heads/master by this push:
     new 58812ee  fix: lazy init and infinite recursion fixes (#5)
58812ee is described below

commit 58812ee50e9d73203f79aef1820cb4ef7aecbf38
Author: vimzoomer <pe...@student.agh.edu.pl>
AuthorDate: Thu Aug 6 08:23:14 2026 +0200

    fix: lazy init and infinite recursion fixes (#5)
---
 README.md                  | 4 ++--
 casbin_adapter/apps.py     | 6 ++----
 casbin_adapter/enforcer.py | 4 ++--
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md
index 080fff0..f5e708e 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@ Based on [Officially Supported Databases](https://docs.djangoproject.com/en/3.0/
 pip install casbin-django-orm-adapter
 ```
 
-Add `casbin_adapter.apps.CasbinAdapterConfig` to your `INSTALLED_APPS`
+Add `casbin_adapter` to your `INSTALLED_APPS`
 
 ```python
 # settings.py
@@ -36,7 +36,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
 INSTALLED_APPS = [
     ...
-    'casbin_adapter.apps.CasbinAdapterConfig',
+    'casbin_adapter',
     ...
 ]
 
diff --git a/casbin_adapter/apps.py b/casbin_adapter/apps.py
index 2674874..28d3b75 100644
--- a/casbin_adapter/apps.py
+++ b/casbin_adapter/apps.py
@@ -6,7 +6,5 @@ class CasbinAdapterConfig(AppConfig):
     name = "casbin_adapter"
 
     def ready(self):
-        from .enforcer import initialize_enforcer
-
-        db_alias = getattr(settings, "CASBIN_DB_ALIAS", "default")
-        initialize_enforcer(db_alias)
+        from .enforcer import enforcer
+        enforcer.db_alias = getattr(settings, "CASBIN_DB_ALIAS", "default")
diff --git a/casbin_adapter/enforcer.py b/casbin_adapter/enforcer.py
index 70d2eaf..4e0d583 100644
--- a/casbin_adapter/enforcer.py
+++ b/casbin_adapter/enforcer.py
@@ -43,9 +43,9 @@ class ProxyEnforcer(Enforcer):
                 self.set_role_manager(role_manager)
 
     def __getattribute__(self, name):
-        safe_methods = ["__init__", "_load", "_initialized"]
+        safe_methods = ["__init__", "__class__", "_load", "_initialized", "db_alias"]
         if not super().__getattribute__("_initialized") and name not in safe_methods:
-            initialize_enforcer(self.db_alias)
+            initialize_enforcer(super().__getattribute__("db_alias"))
             if not super().__getattribute__("_initialized"):
                 raise Exception(
                     (


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For additional commands, e-mail: commits-help@casbin.apache.org