diff --git a/apps/amo/tasks.py b/apps/amo/tasks.py index 3d48d5c89f..bd40b8f0d4 100644 --- a/apps/amo/tasks.py +++ b/apps/amo/tasks.py @@ -50,7 +50,7 @@ def dedupe_approvals(items, **kw): for addon in Addon.objects.filter(pk__in=items): last = {} for activity in (ActivityLog.objects.for_addons(addon) - .order_by('-id') + .order_by('-created') .filter(action__in=LOG_STATUSES)): arguments = json.loads(activity._arguments) current = { @@ -71,4 +71,5 @@ def dedupe_approvals(items, **kw): log.info('Deleting duplicate activity log %s ' 'from addon %s' % (activity.pk, addon.pk)) activity.delete() - last = current.copy() + else: + last = current.copy() diff --git a/apps/amo/tests/test_cron.py b/apps/amo/tests/test_cron.py index c42fb8737a..8e213a62d6 100644 --- a/apps/amo/tests/test_cron.py +++ b/apps/amo/tests/test_cron.py @@ -117,3 +117,14 @@ class TestDedupeApprovals(test_utils.TestCase): amo.log(amo.LOG.APPROVE_VERSION, self.addon, self.version) dedupe_approvals([self.addon.pk]) eq_(ActivityLog.objects.for_addons(self.addon).count(), 2) + + def test_dedupe_not_id(self): + date_one = datetime.today() + date_two = datetime.today() - timedelta(days=1) + for x in range(0, 4): + log = amo.log(amo.LOG.APPROVE_VERSION, self.addon, self.version) + log.update(created=date_one) + log = amo.log(amo.LOG.REJECT_VERSION, self.addon, self.version) + log.update(created=date_two) + dedupe_approvals([self.addon.pk]) + eq_(ActivityLog.objects.for_addons(self.addon).count(), 2)