Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: initialize with db_alias #24

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion casbin_adapter/apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.apps import AppConfig
from django.conf import settings


class CasbinAdapterConfig(AppConfig):
Expand All @@ -7,4 +8,5 @@ class CasbinAdapterConfig(AppConfig):
def ready(self):
from .enforcer import initialize_enforcer

initialize_enforcer()
db_alias = getattr(settings, "CASBIN_DB_ALIAS", "default")
initialize_enforcer(db_alias)
4 changes: 2 additions & 2 deletions casbin_adapter/enforcer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from django.conf import settings
from django.db import connection
from django.db import connection, connections
from django.db.utils import OperationalError, ProgrammingError

from casbin import Enforcer
Expand Down Expand Up @@ -64,7 +64,7 @@ def initialize_enforcer(db_alias=None):
try:
row = None
if db_alias:
with connection[db_alias].cursor() as cursor:
with connections[db_alias].cursor() as cursor:
cursor.execute(
"""
SELECT app, name applied FROM django_migrations
Expand Down