Skip to content

Add group name validation for subgroups

sameer shaik requested to merge valid-subgroup into master

What does this MR do and why?

This MR intends to resolve the following bug: #346883 (closed)

An attempt to create a subgroup with the same name as an existing subgroup returns a 500 error.

Logs:

ActiveRecord::RecordNotUnique
PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_namespaces_name_parent_id_type"

DETAIL:  Key (name, parent_id, type)=(SOMEGROUP, 111111, Group) already exists.
PG::UniqueViolation

ERROR:  duplicate key value violates unique constraint "index_namespaces_name_parent_id_type"

It seems like, the unique index was modified in this MR: !71390 (merged). There are no validations in the group model.

The lookup is using index. However, I'm not sure about the performance impact as it's a group level validation(conditional).

> Group.where(name: "subgroup", parent_id: 33).explain

 Index Scan using index_groups_on_parent_id_id on namespaces  (cost=0.13..2.15 rows=1 width=379)
   Index Cond: (parent_id = 33)
   Filter: ((name)::text = 'subgroup'::text)
(3 rows)

Screenshots or screen recordings

Before:

Screenshot_2022-11-14_at_6.53.32_PM

After:

Screenshot_2022-11-14_at_7.05.38_PM

How to set up and validate locally

  1. Checkout this branch
  2. Create a group and a subgroup
  3. Create another subgroup with the same name
  4. Notice that the UI shows validation errors instead of 500 error

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by sameer shaik

Merge request reports