Repository: ietf-tools/datatracker

Issue:
Session Request: After requesting info from IETF-113, Chairs were not recognized in Datatracker...
### What happened?

After requesting info from IETF-113, Error Message for "bethere" said Chairs were not recognized in Datatracker. I pressed submit anyway and the Session request submission failed.

### What browser(s) are you seeing the problem on?

Firefox

### Code of Conduct

- [X] I agree to follow the IETF's Code of Conduct


Discussion:
This was for BMWG session at IETF-114.  New issue, AFAICT.
A server error corresponding to this also occurred. From that:

```
ValueError at /secr/sreq/bmwg/confirm/ invalid literal for int() with base 10: '<QuerySet [<Person: **REDACTED**>]>'
```

Guessing it's a bug to do with the select2 integration, which plays some tricks with integer keys in the form fields.
fwiw:
![image](https://user-images.githubusercontent.com/10996692/165365948-9f51055a-66a1-4011-9a9d-f59e258fb128.png)

There's something going wrong on the `new()` view - the `bethere` field is not being submitted with the correct value. E.g., I submitted a request with three people selected as "bethere", but:
```
(Pdb) pp request.POST
{'adjacent_with_wg': '',
 'attendees': '25',
 'bethere': '111656',
```
That number (111656) is the PK for one of the selected people, but a couple have been dropped.


Edit: Oops - false start here, the appearance of missing values in the `bethere` field is a Django artifact. Using `request.POST.getlist('bethere')` shows the three expected PKs.

Resolving patch:
diff --git a/ietf/secr/sreq/forms.py b/ietf/secr/sreq/forms.py
--- a/ietf/secr/sreq/forms.py
+++ b/ietf/secr/sreq/forms.py
@@ -11,6 +11,7 @@
 from ietf.meeting.forms import sessiondetailsformset_factory
 from ietf.meeting.models import ResourceAssociation, Constraint
 from ietf.person.fields import SearchablePersonsField
+from ietf.person.models import Person
 from ietf.utils.html import clean_text_field
 from ietf.utils import log
 
@@ -154,10 +155,17 @@ def __init__(self, group, meeting, data=None, *args, **kwargs):
         self.fields["resources"].choices = [(x.pk,x.desc) for x in ResourceAssociation.objects.filter(name__used=True).order_by('name__order') ]
 
         if self.hidden:
+            # replace all the widgets to start...
             for key in list(self.fields.keys()):
                 self.fields[key].widget = forms.HiddenInput()
+            # re-replace a couple special cases
             self.fields['resources'].widget = forms.MultipleHiddenInput()
             self.fields['timeranges'].widget = forms.MultipleHiddenInput()
+            # and entirely replace bethere - no need to support searching if input is hidden
+            self.fields['bethere'] = forms.ModelMultipleChoiceField(
+                widget=forms.MultipleHiddenInput, required=False,
+                queryset=Person.objects.all(),
+            )
 
     def wg_constraint_fields(self):
         """Iterates over wg constraint fields
diff --git a/ietf/secr/sreq/views.py b/ietf/secr/sreq/views.py
--- a/ietf/secr/sreq/views.py
+++ b/ietf/secr/sreq/views.py
@@ -289,9 +289,8 @@ def confirm(request, acronym):
         return redirect('ietf.secr.sreq.views.main')
                 
     session_data = form.data.copy()
-    if 'bethere' in session_data:
-        person_id_list = [ id for id in form.data['bethere'].split(',') if id ]
-        session_data['bethere'] = Person.objects.filter(pk__in=person_id_list)
+    # use cleaned_data for the 'bethere' field so we get the Person instances
+    session_data['bethere'] = form.cleaned_data['bethere'] if 'bethere' in form.cleaned_data else []
     if session_data.get('session_time_relation'):
         session_data['session_time_relation_display'] = dict(Constraint.TIME_RELATION_CHOICES)[session_data['session_time_relation']]
     if session_data.get('joint_for_session'):


Test patch: