From e14b4f67e20b5ea8d6a3fd4d4b67064a7251abb4 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 26 Oct 2022 17:05:38 +0200 Subject: Geodata post save: transactions and targeted post save to limit deadlocks --- archaeological_context_records/models.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'archaeological_context_records') diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 97a629d05..55b101acc 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -23,10 +23,9 @@ import uuid from django.apps import apps from django.conf import settings from django.contrib.gis.db import models -from django.contrib.gis.geos import Point from django.contrib.postgres.indexes import GinIndex from django.contrib.sites.models import Site -from django.db import connection +from django.db import connection, IntegrityError, transaction from django.db.models import Q from django.db.models.signals import post_delete, post_save, m2m_changed from django.urls import reverse @@ -458,11 +457,15 @@ class GeographicSubTownItem(GeoItem): return if not q_geodata_current_town.filter(source_id=town.id).count(): - self.geodata.add(town.main_geodata) + try: + # multiple save, post treatments can cause synchronous add + with transaction.atomic(): + self.geodata.add(town.main_geodata) + except IntegrityError: + pass if save: - self.skip_history_when_saving = True - self._no_move = True - self.save() + post_save_geo(self.__class__, instance=self, created=False, + update_fields=False, raw=False, using="default") else: return True -- cgit v1.2.3