Bug #5129
closedHost Group creation may fail if Host Group with id 1 exists with same parameter name
Description
I believe the cause is similar to issue #4731. On a production RHEL or Centos install, when creating a Host Group and specifying some parameter, if a host group with ID = 1 already exists with that same parameter name the creation will fail with error "Name has already been taken". The cause is that when this validation is run:
validates :name, :uniqueness => {:scope => :reference_id}
The new parameter's reference_id is set to 1 instead of nil. Thus if a host group already exists with this parameter name (and that host group has an ID of 1), the validation will fail.
Here is an example of a validation:
GroupParameter Exists (0.2ms) SELECT 1 AS one FROM "parameters" WHERE "parameters"."type" IN ('GroupParameter') AND ("parameters"."name" = 'kt_org' AND "parameters"."reference_id" = 1) LIMIT 1
This was the sql generated with a new host group submission.
NOTE: this will not occur on a development install using the latest version of Rails 3.2.