From 88ab66749e427a4a9e0af37151b5c3f1995be652 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 15 Nov 2019 22:42:11 -0400 Subject: [PATCH] Self-heal statistics results model Happens when multiple results are created using the same slug value. Forum topic 1404. Signed-off-by: Roberto Rosario --- HISTORY.rst | 3 +++ mayan/apps/mayan_statistics/classes.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index 6d13f506ae..18f024ff03 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -9,6 +9,9 @@ generalized utility of the storages app. - Add book link to the documentation. - Make the statistics slug field unique. +- Self-heal statistics results model when multiple + results are created using the same slug value. + Forum topic 1404. 3.2.10 (2019-11-19) =================== diff --git a/mayan/apps/mayan_statistics/classes.py b/mayan/apps/mayan_statistics/classes.py index e4296d095f..ff0c93c896 100644 --- a/mayan/apps/mayan_statistics/classes.py +++ b/mayan/apps/mayan_statistics/classes.py @@ -158,6 +158,11 @@ class Statistic(object): return StatisticResult.objects.get(slug=self.slug) except StatisticResult.DoesNotExist: return StatisticResult.objects.none() + except StatisticResult.MultipleObjectsReturned: + # This should not happen. Self-heal by deleting the duplicate + # results. + StatisticResult.objects.filter(slug=self.slug).delete() + return StatisticResult.objects.none() def get_results_data(self): results = self.get_results()