From 6c7078317486d282318940e5f75f1a938f46b52c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Gon=C3=A7alves?= Date: Tue, 22 Feb 2022 18:44:23 -0300 Subject: [PATCH] enable use of replica database When you use replica database the django-auditlog try to write in the same database where object was read (replica). But this is a read only database and crash the application. This changes saves always in the default database. If you want to save in multiple databases or in a special one use `DATABASE_ROUTERS` to configure it. --- auditlog/models.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/auditlog/models.py b/auditlog/models.py index 606c604..a50ead7 100644 --- a/auditlog/models.py +++ b/auditlog/models.py @@ -67,13 +67,7 @@ class LogEntryManager(models.Manager): content_type=kwargs.get("content_type"), object_pk=kwargs.get("object_pk", ""), ).delete() - # save LogEntry to same database instance is using - db = instance._state.db - return ( - self.create(**kwargs) - if db is None or db == "" - else self.using(db).create(**kwargs) - ) + return self.create(**kwargs) return None def get_for_object(self, instance):