Skip to content

Commit 704ef61

Browse files
committed
implement workaround for psycopg3
1 parent d00e7b7 commit 704ef61

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ephios/modellogging/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import json
2+
13
from django.conf import settings
24
from django.contrib.contenttypes.fields import GenericForeignKey
35
from django.contrib.contenttypes.models import ContentType
46
from django.db import models
7+
from django.db.models.signals import pre_save
8+
from django.dispatch import receiver
59
from django.utils.functional import cached_property
610
from django.utils.translation import gettext_lazy as _
711

@@ -76,3 +80,11 @@ def __str__(self):
7680
if self.content_object:
7781
return f"{self.action_type} {type(self.content_object)._meta.verbose_name} {str(self.content_object)}"
7882
return f"{self.action_type} {self.content_type.model} {self.content_object_or_str}"
83+
84+
85+
86+
@receiver(pre_save, sender=LogEntry)
87+
def encode_data_for_psycopg3(sender, instance, raw, using, update_fields, **kwargs):
88+
# psycopg3 does not allow read operations on the database while the model is being saved.
89+
# details and source of this workaround: https://forum.djangoproject.com/t/connection-lock-hanging-after-upgrading-psycopg/30826/3
90+
instance.data = json.loads(LogJSONEncoder().encode(instance.data))

0 commit comments

Comments
 (0)