diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-10-27 13:55:43 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:23:19 +0100 | 
| commit | 9589747a947df6550729b6adae89618aa7839f4e (patch) | |
| tree | 63b34c04e9adf4088384240cbf50500bfc26d2fc /archaeological_operations/models.py | |
| parent | 7ab38503a2450b11e72ed28445b080e5a6cf27f4 (diff) | |
| download | Ishtar-9589747a947df6550729b6adae89618aa7839f4e.tar.bz2 Ishtar-9589747a947df6550729b6adae89618aa7839f4e.zip  | |
Geodata save: transaction for main_geodata assignation to limit deadlocks
Diffstat (limited to 'archaeological_operations/models.py')
| -rw-r--r-- | archaeological_operations/models.py | 20 | 
1 files changed, 10 insertions, 10 deletions
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  | 
