summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.md9
-rw-r--r--archaeological_context_records/models.py4
-rw-r--r--archaeological_operations/models.py20
-rw-r--r--ishtar_common/models_common.py11
-rw-r--r--ishtar_common/version.py4
5 files changed, 30 insertions, 18 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 2bf47cf25..cd03926e6 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,8 +1,15 @@
---
title: Ishtar changelog
-date: 2022-10-19
+date: 2022-10-17
---
+v4.0.24 - 2022-10-27
+--------------------
+
+### Bug fix ###
+- Geodata save: transactions to limit deadlocks
+
+
v4.0.23 - 2022-10-26
--------------------
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 55b101acc..09733b566 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -25,7 +25,7 @@ from django.conf import settings
from django.contrib.gis.db import models
from django.contrib.postgres.indexes import GinIndex
from django.contrib.sites.models import Site
-from django.db import connection, IntegrityError, transaction
+from django.db import connection, transaction, OperationalError, IntegrityError
from django.db.models import Q
from django.db.models.signals import post_delete, post_save, m2m_changed
from django.urls import reverse
@@ -461,7 +461,7 @@ class GeographicSubTownItem(GeoItem):
# multiple save, post treatments can cause synchronous add
with transaction.atomic():
self.geodata.add(town.main_geodata)
- except IntegrityError:
+ except (OperationalError, IntegrityError):
pass
if save:
post_save_geo(self.__class__, instance=self, created=False,
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 6cbac457e..0888345d7 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -31,7 +31,7 @@ from django.contrib.gis.db.models.aggregates import Union
from django.contrib.gis.db.models.functions import Centroid
from django.contrib.postgres.indexes import GinIndex
from django.contrib.sites.models import Site
-from django.db import IntegrityError, transaction
+from django.db import transaction, OperationalError, IntegrityError
from django.db.models import Q, Count, Sum, Max, Avg
from django.db.models.signals import post_save, m2m_changed, post_delete
from django.forms import ValidationError
@@ -194,7 +194,7 @@ class GeographicTownItem(GeoItem):
if self.main_geodata == geo:
self.main_geodata = None
changed = True
- except IntegrityError:
+ except (OperationalError, IntegrityError):
pass
if q_towns_nb < 2:
# no area - clean
@@ -205,7 +205,7 @@ class GeographicTownItem(GeoItem):
if self.main_geodata == geo:
self.main_geodata = None
changed = True
- except IntegrityError:
+ except (OperationalError, IntegrityError):
pass
current_town_geo = None
@@ -218,7 +218,7 @@ class GeographicTownItem(GeoItem):
if self.main_geodata == geo:
self.main_geodata = None
changed = True
- except IntegrityError:
+ except (OperationalError, IntegrityError):
pass
if not q_geodata_town.filter(source_id=current_town_geo.pk).count():
self.geodata.add(current_town_geo.main_geodata)
@@ -237,13 +237,13 @@ class GeographicTownItem(GeoItem):
self.geodata.remove(geo)
if self.main_geodata == geo:
self.main_geodata = None
- except IntegrityError:
+ except (OperationalError, IntegrityError):
pass
try:
with transaction.atomic():
self.geodata.add(current_geo_area)
changed = True
- except IntegrityError:
+ except (OperationalError, IntegrityError):
pass
if current_town_geo:
@@ -257,7 +257,7 @@ class GeographicTownItem(GeoItem):
if self.main_geodata == geo:
self.main_geodata = None
changed = True
- except IntegrityError:
+ except (OperationalError, IntegrityError):
pass
if current_geo_area:
q_extra_geo_area = q_geodata_area.exclude(pk=current_geo_area.pk)
@@ -270,7 +270,7 @@ class GeographicTownItem(GeoItem):
if self.main_geodata == geo:
self.main_geodata = None
changed = True
- except IntegrityError:
+ except (OperationalError, IntegrityError):
pass
if changed and save:
@@ -3236,7 +3236,7 @@ def parcel_post_save(sender, **kwargs):
# multiple save can cause multiple add
with transaction.atomic():
parcel.operation.towns.add(parcel.town)
- except IntegrityError:
+ except (OperationalError, IntegrityError):
pass
if (
parcel.associated_file
@@ -3247,7 +3247,7 @@ def parcel_post_save(sender, **kwargs):
# multiple save can cause multiple add
with transaction.atomic():
parcel.associated_file.towns.add(parcel.town)
- except IntegrityError:
+ except (OperationalError, IntegrityError):
pass
if parcel.operation and parcel.associated_file:
# parcels are copied between files and operations
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index 6330742a3..1c77d1a90 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -36,7 +36,7 @@ from django.core.files import File
from django.core.serializers import serialize
from django.urls import reverse, NoReverseMatch
from django.core.validators import validate_slug
-from django.db import connection
+from django.db import connection, transaction, OperationalError, IntegrityError
from django.db.models import Q, Count, Max
from django.db.models.signals import post_save, post_delete, m2m_changed
from django.template import loader
@@ -2724,8 +2724,13 @@ class GeographicItem(models.Model):
using=using,
update_fields=update_fields,
)
- if self.main_geodata and not self.geodata.filter(pk=self.main_geodata.pk).count():
- self.geodata.add(self.main_geodata)
+ if self.main_geodata and not self.geodata.filter(
+ pk=self.main_geodata.pk).count():
+ try:
+ with transaction.atomic():
+ self.geodata.add(self.main_geodata)
+ except (OperationalError, IntegrityError):
+ pass
elif not self.main_geodata and self.geodata.count():
# arbitrary associate the first to geodata
self.main_geodata = self.geodata.order_by("pk").all()[0]
diff --git a/ishtar_common/version.py b/ishtar_common/version.py
index 08bf33274..ad8f491b9 100644
--- a/ishtar_common/version.py
+++ b/ishtar_common/version.py
@@ -1,5 +1,5 @@
-# 4.0.23
-VERSION = (4, 0, 23)
+# 4.0.24
+VERSION = (4, 0, 24)
def get_version():