diff options
Diffstat (limited to 'ishtar_common/models_common.py')
-rw-r--r-- | ishtar_common/models_common.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index e4438be43..928b22630 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2946,12 +2946,17 @@ class GeographicItem(models.Model): 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] - self.skip_history_when_saving = True - self._no_move = True - self.save() + elif not self.main_geodata: + try: + with transaction.atomic(): + if self.geodata.count(): + # arbitrary associate the first to geodata + self.main_geodata = self.geodata.order_by("pk").all()[0] + self.skip_history_when_saving = True + self._no_move = True + self.save() + except (OperationalError, IntegrityError, IndexError): + pass @property def geodata_list(self): |