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 Session error when using a custom session app #317

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions easyaudit/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.conf import settings
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.contrib.sessions.models import Session
from django.db.migrations import Migration
from django.db.migrations.recorder import MigrationRecorder

Expand Down Expand Up @@ -48,7 +47,6 @@ def get_model_list(class_list):
LoginEvent,
RequestEvent,
Migration,
Session,
Permission,
ContentType,
MigrationRecorder.Migration,
Expand All @@ -60,6 +58,12 @@ def get_model_list(class_list):

UNREGISTERED_CLASSES += [LogEntry]

# Import and unregister Session class only if Django Sessions app is installed
if apps.is_installed("django.contrib.sessions"):
from django.contrib.sessions.models import Session

UNREGISTERED_CLASSES += [Session]

UNREGISTERED_CLASSES = getattr(
settings, "DJANGO_EASY_AUDIT_UNREGISTERED_CLASSES_DEFAULT", UNREGISTERED_CLASSES
)
Expand Down
4 changes: 2 additions & 2 deletions easyaudit/signals/request_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.conf import settings
from django.contrib.auth import SESSION_KEY as AUTH_SESSION_KEY
from django.contrib.auth import get_user_model
from django.contrib.sessions.models import Session
from django.core.exceptions import ObjectDoesNotExist
from django.core.signals import request_started
from django.http.cookie import SimpleCookie
from django.utils import timezone
Expand Down Expand Up @@ -75,7 +75,7 @@ def request_started_handler(sender, **kwargs):

try:
session = session_engine.SessionStore(session_key=session_id).load()
except Session.DoesNotExist:
except ObjectDoesNotExist:
session = None

if session and AUTH_SESSION_KEY in session:
Expand Down