anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: line/promgen
Issue: Register Service with existing name

When trying to register a service with an already existing name the view crashes (500: Internal Server Error).

[traceback.txt](https://github.com/line/promgen/files/1691856/traceback.txt)

Steps to reproduce:

 1. Create shard: "Shard 1"
 2. Create shart: "Shard 2"
 3. Register service in "Shard 1" with name "Default Service"
 4. Register service in "Shard 2" with name "Default Service"

Interestingly this issue does not occur when creating projects with the same name. Here, an appropriate error message is displayed.

Changed files:
promgen/forms.py, promgen/views.py

diff --git a/promgen/forms.py b/promgen/forms.py
index fd980f4..3270341 100644
--- a/promgen/forms.py
+++ b/promgen/forms.py
@@ -90,19 +90,26 @@ class ExporterForm(forms.ModelForm):
         }
 
 
-class ServiceForm(forms.ModelForm):
+class ServiceRegister(forms.ModelForm):
+    class Meta:
+        model = models.Service
+        # shard is determined by the pk in the service register url
+        exclude = ['shard']
+
+
+class ServiceUpdate(forms.ModelForm):
     class Meta:
         model = models.Service
         exclude = []
 
 
-class ProjectForm(forms.ModelForm):
+class ProjectRegister(forms.ModelForm):
     class Meta:
         model = models.Project
         exclude = ['service', 'farm']
 
 
-class ProjectMove(forms.ModelForm):
+class ProjectUpdate(forms.ModelForm):
     class Meta:
         model = models.Project
         exclude = ['farm']
diff --git a/promgen/views.py b/promgen/views.py
index f47b919..6c087a8 100644
--- a/promgen/views.py
+++ b/promgen/views.py
@@ -569,7 +569,7 @@ class ProjectRegister(LoginRequiredMixin, FormView, ServiceMixin):
     button_label = _('Project Register')
     model = models.Project
     template_name = 'promgen/project_form.html'
-    form_class = forms.ProjectForm
+    form_class = forms.ProjectRegister
 
     def form_valid(self, form):
         service = get_object_or_404(models.Service, id=self.kwargs['pk'])
@@ -581,7 +581,7 @@ class ProjectUpdate(LoginRequiredMixin, UpdateView):
     model = models.Project
     button_label = _('Project Update')
     template_name = 'promgen/project_form.html'
-    form_class = forms.ProjectMove
+    form_class = forms.ProjectUpdate
 
     def get_context_data(self, **kwargs):
         context = super(ProjectUpdate, self).get_context_data(**kwargs)
@@ -591,7 +591,7 @@ class ProjectUpdate(LoginRequiredMixin, UpdateView):
 
 class ServiceUpdate(LoginRequiredMixin, UpdateView):
     button_label = _('Update Service')
-    form_class = forms.ServiceForm
+    form_class = forms.ServiceUpdate
     model = models.Service
     template_name = 'promgen/service_form.html'
 
@@ -706,7 +706,7 @@ class RuleRegister(LoginRequiredMixin, FormView, ServiceMixin):
 
 class ServiceRegister(LoginRequiredMixin, FormView):
     button_label = _('Service Register')
-    form_class = forms.ProjectForm
+    form_class = forms.ServiceRegister
     model = models.Service
     template_name = 'promgen/service_form.html'