Skip to content

Commit 1ce5ce9

Browse files
committed
[AAP-23882] - Creating a new Team with the same name should not propagate IntegrityError
1 parent 3572081 commit 1ce5ce9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/aap_eda/api/serializers/team.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class Meta:
5757

5858
def validate(self, data):
5959
self.validate_shared_resource()
60+
validators.check_if_team_name_exists(
61+
data["name"], data["organization_id"]
62+
)
6063
return data
6164

6265

src/aap_eda/core/validators.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,16 @@ def check_credential_types(
235235
raise serializers.ValidationError(
236236
f"The type of credential can only be one of {names}"
237237
)
238+
239+
240+
def check_if_team_name_exists(name: str, organization_id: int):
241+
if models.Team.objects.filter(
242+
name=name, organization_id=organization_id
243+
).exists():
244+
raise serializers.ValidationError(
245+
{
246+
"name": [
247+
"A team with this name already exists in the organization."
248+
]
249+
}
250+
)

0 commit comments

Comments
 (0)