From 5b0fd0d5d8fe2cdae6d8bc8398fdb907bff2de7b Mon Sep 17 00:00:00 2001 From: FerZunzu98 Date: Mon, 15 Jul 2024 14:06:39 +0200 Subject: [PATCH 1/2] fix: MultipleObjectsReturned error in left object in get neighbors --- taiga/base/neighbors.py | 2 +- tests/integration/test_neighbors.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/taiga/base/neighbors.py b/taiga/base/neighbors.py index adfc706d..60e52272 100644 --- a/taiga/base/neighbors.py +++ b/taiga/base/neighbors.py @@ -64,7 +64,7 @@ def get_neighbors(obj, results_set=None): right_object_id = row[3] try: - left = results_set.get(id=left_object_id) + left = results_set.filter(id=left_object_id).first() except ObjectDoesNotExist: left = None diff --git a/tests/integration/test_neighbors.py b/tests/integration/test_neighbors.py index 3a2c4df6..6053bcb9 100644 --- a/tests/integration/test_neighbors.py +++ b/tests/integration/test_neighbors.py @@ -48,6 +48,20 @@ def test_results_set_repeat_id(self): assert neighbors.right == us1 + def test_results_set_left_repeat_id(self): + project = f.ProjectFactory.create() + + us1 = f.UserStoryFactory.create(project=project) + f.RolePointsFactory.create(user_story=us1) + f.RolePointsFactory.create(user_story=us1) + + us2 = f.UserStoryFactory.create(project=project) + f.RolePointsFactory.create(user_story=us2) + + neighbors = n.get_neighbors(us2, results_set=UserStory.objects.get_queryset().filter(role_points__isnull=False)) + + assert neighbors.left == us1 + def test_filtered_by_tags(self): tag_names = ["test"] project = f.ProjectFactory.create() From a0f68755c1992202dbe2bbe427e86463aee34370 Mon Sep 17 00:00:00 2001 From: ferzunzu Date: Fri, 26 Jul 2024 11:13:59 +0200 Subject: [PATCH 2/2] Fixed bug with data_finish. Now the finish date of a task needs to be greater than the start date. --- taiga/projects/milestones/models.py | 4 ++++ .../test_milestones_resources.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/taiga/projects/milestones/models.py b/taiga/projects/milestones/models.py index b43b43f3..3c6a463c 100644 --- a/taiga/projects/milestones/models.py +++ b/taiga/projects/milestones/models.py @@ -72,6 +72,10 @@ def __repr__(self): return "".format(self.id) def clean(self): + + if self.estimated_start and self.estimated_start.year == datetime.MAXYEAR: + raise ValidationError(_("Invalid estimated start year, it must be less than 9999.")) + # Don't allow draft entries to have a pub_date. if self.estimated_start and self.estimated_finish and self.estimated_start > self.estimated_finish: raise ValidationError(_('The estimated start must be previous to the estimated finish.')) diff --git a/tests/integration/resources_permissions/test_milestones_resources.py b/tests/integration/resources_permissions/test_milestones_resources.py index b7a063a9..03790dc2 100644 --- a/tests/integration/resources_permissions/test_milestones_resources.py +++ b/tests/integration/resources_permissions/test_milestones_resources.py @@ -295,6 +295,23 @@ def test_milestone_create(client, data): assert results == [401, 403, 403, 451, 451] +def test_milestone_create_invalid_dates(client, data): + url = reverse('milestones-list') + + user = data.project_owner + create_data = json.dumps({ + "name": "test", + "estimated_start": "9999-12-10", + "estimated_finish": "9999-12-24", + "project": data.public_project.pk, + }) + + client.login(user) + + response = client.post(url, create_data, content_type="application/json") + assert response.status_code == 400 + assert response.data["__all__"][0] == "Invalid estimated start year, it must be less than 9999." + def test_milestone_patch(client, data): public_url = reverse('milestones-detail', kwargs={"pk": data.public_milestone.pk}) private_url1 = reverse('milestones-detail', kwargs={"pk": data.private_milestone1.pk})