Repository: weni-ai/bothub-engine

Issue:
Repository examples method ignore deleted when language is setted
Check this line..
https://github.com/Ilhasoft/bothub-engine/blob/master/bothub/common/models.py#L218


Discussion:

Resolving patch:
diff --git a/bothub/common/models.py b/bothub/common/models.py
--- a/bothub/common/models.py
+++ b/bothub/common/models.py
@@ -333,7 +333,7 @@ def examples(self):
                 models.Q(deleted_in=self) |
                 models.Q(deleted_in__training_started_at__lt=t_started_at))
         else:
-            examples = examples.exclude(deleted_in=self)
+            examples = examples.exclude(deleted_in__isnull=False)
         return examples
 
     @property
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
 
 setup(
     name='bothub',
-    version='1.14.2',
+    version='1.14.3',
     description='bothub',
     packages=find_packages(),
     install_requires=[


Test patch:
diff --git a/bothub/common/tests.py b/bothub/common/tests.py
--- a/bothub/common/tests.py
+++ b/bothub/common/tests.py
@@ -352,7 +352,7 @@ def test_language(self):
             self.example.language,
             self.language)
 
-    def teste_delete(self):
+    def test_delete(self):
         self.example.delete()
         self.assertEqual(
             self.example.deleted_in,
@@ -575,6 +575,11 @@ def setUp(self):
             repository_update=self.repository.current_update(),
             text='hi',
             intent='greet')
+        example = RepositoryExample.objects.create(
+            repository_update=self.repository.current_update(),
+            text='hello1',
+            intent='greet')
+        example.delete()
 
         self.update = self.repository.current_update()
         self.update.start_training(self.owner)
@@ -604,6 +609,71 @@ def test_okay(self):
             new_update_2.examples.count(),
             3)
 
+    def test_examples_deleted_consistency(self):
+        new_update_1 = self.repository.current_update()
+        RepositoryExample.objects.create(
+            repository_update=new_update_1,
+            text='hello',
+            intent='greet')
+        RepositoryExample.objects.create(
+            repository_update=new_update_1,
+            text='hello d1',
+            intent='greet').delete()
+        examples_1_count = new_update_1.examples.count()
+        new_update_1.start_training(self.owner)
+
+        new_update_2 = self.repository.current_update()
+        RepositoryExample.objects.create(
+            repository_update=new_update_2,
+            text='hellow',
+            intent='greet')
+        examples_2_count = new_update_2.examples.count()
+        new_update_2.start_training(self.owner)
+
+        new_update_3 = self.repository.current_update()
+        RepositoryExample.objects.create(
+            repository_update=new_update_3,
+            text='hellow',
+            intent='greet')
+        RepositoryExample.objects.create(
+            repository_update=new_update_3,
+            text='hello d2',
+            intent='greet').delete()
+        RepositoryExample.objects.create(
+            repository_update=new_update_3,
+            text='hello d3',
+            intent='greet').delete()
+        RepositoryExample.objects.create(
+            repository_update=new_update_3,
+            text='hello d4',
+            intent='greet').delete()
+        examples_3_count = new_update_3.examples.count()
+        new_update_3.start_training(self.owner)
+
+        new_update_4 = self.repository.current_update()
+        RepositoryExample.objects.create(
+            repository_update=new_update_4,
+            text='hellow',
+            intent='greet')
+        examples_4_count = new_update_4.examples.count()
+        new_update_4.start_training(self.owner)
+
+        self.assertEqual(
+            examples_1_count,
+            new_update_1.examples.count())
+
+        self.assertEqual(
+            examples_2_count,
+            new_update_2.examples.count())
+
+        self.assertEqual(
+            examples_3_count,
+            new_update_3.examples.count())
+
+        self.assertEqual(
+            examples_4_count,
+            new_update_4.examples.count())
+
 
 class RepositoryReadyForTrain(TestCase):
     def setUp(self):