diff --git a/taiga/projects/models.py b/taiga/projects/models.py index 8df7ac37..7e4e36d5 100644 --- a/taiga/projects/models.py +++ b/taiga/projects/models.py @@ -224,16 +224,17 @@ class Project(ProjectDefaults, TaggedMixin, models.Model): user_stories = self.user_stories.all() # Get point instance that represent a null/undefined - # The current model allows dulplicate values. Because + # The current model allows duplicate values. Because # of it, we should get all poins with None as value # and use the first one. # In case of that not exists, creates one for avoid - # unxpected errors. + # unexpected errors. none_points = list(self.points.filter(value=None)) if none_points: null_points_value = none_points[0] else: - null_points_value = Points.objects.create(name="?", value=None, project=self) + name = slugify_uniquely_for_queryset("?", self.points.all(), slugfield="name") + null_points_value = Points.objects.create(name=name, value=None, project=self) for us in user_stories: usroles = Role.objects.filter(role_points__in=us.role_points.all()).distinct() diff --git a/tests/integration/test_projects.py b/tests/integration/test_projects.py index 6ad65fbe..7178362c 100644 --- a/tests/integration/test_projects.py +++ b/tests/integration/test_projects.py @@ -84,7 +84,6 @@ def test_issue_status_slug_generation(client): assert response.status_code == 200 assert response.data["slug"] == "new-status" - def test_points_name_duplicated(client): point_1 = f.PointsFactory() point_2 = f.PointsFactory(project=point_1.project) @@ -96,3 +95,10 @@ def test_points_name_duplicated(client): response = client.json.patch(url, json.dumps(data)) assert response.status_code == 400 assert response.data["name"][0] == "Name duplicated for the project" + +def test_update_points_when_not_null_values_for_points(client): + points = f.PointsFactory(name="?", value="6") + role = f.RoleFactory(project=points.project, computable=True) + assert points.project.points.filter(value__isnull=True).count() == 0 + points.project.update_role_points() + assert points.project.points.filter(value__isnull=True).count() == 1