Repository: fedora-infra/bodhi

Issue:
New bodhi updates are "Logout required" by default
Go to https://bodhi.fedoraproject.org/updates/new

The *Suggestion* now defaults to *logout*.

Is this new policy or a mistake? I see some logout updates in bodhi where it is most likely not needed.

I've filled this as [an infra issue](https://pagure.io/fedora-infrastructure/issue/7396), got redirected here.


Discussion:
https://github.com/fedora-infra/bodhi/pull/2777
It turns out that Python 3 sorts these entries differently than Python 2 does. Running Bodhi with ```pserve-2``` does not show this issue, but running it with ```pserve-3``` does.
Don't know what entries are there, but if it has something to do with dict, Python 3.6+ maintains insertion order (as language standard in 3.7+).
@hroncok Oh that's an interesting possibility. I'll look into that. It turns out that #2777 did not fix this issue, so I'm going to see if I can figure it out now.

Resolving patch:
diff --git a/bodhi/server/services/updates.py b/bodhi/server/services/updates.py
--- a/bodhi/server/services/updates.py
+++ b/bodhi/server/services/updates.py
@@ -26,6 +26,7 @@
 from sqlalchemy import func, distinct
 from sqlalchemy.sql import or_
 from requests import RequestException, Timeout as RequestsTimeout
+import six
 
 from bodhi.server import log, security
 from bodhi.server.exceptions import BodhiException, LockedUpdateException
@@ -147,12 +148,15 @@ def get_update_for_editing(request):
             severities: The possible values for update severity.
             suggestions: The possible values for update suggestion.
     """
+    suggestions = list(bodhi.server.models.UpdateSuggestion.values())
+    if six.PY2:  # pragma: no cover
+        suggestions = reversed(suggestions)
     return dict(
         update=request.validated['update'],
         types=reversed(list(bodhi.server.models.UpdateType.values())),
         severities=sorted(
             list(bodhi.server.models.UpdateSeverity.values()), key=bodhi.server.util.sort_severity),
-        suggestions=reversed(list(bodhi.server.models.UpdateSuggestion.values())),
+        suggestions=suggestions,
     )
 
 
diff --git a/bodhi/server/views/generic.py b/bodhi/server/views/generic.py
--- a/bodhi/server/views/generic.py
+++ b/bodhi/server/views/generic.py
@@ -241,12 +241,15 @@ def new_update(request):
     user = request.authenticated_userid
     if not user:
         raise HTTPForbidden("You must be logged in.")
+    suggestions = list(models.UpdateSuggestion.values())
+    if six.PY2:  # pragma: no cover
+        suggestions = reversed(suggestions)
     return dict(
         update=None,
         types=reversed(list(models.UpdateType.values())),
         severities=sorted(list(models.UpdateSeverity.values()),
                           key=bodhi.server.util.sort_severity),
-        suggestions=reversed(list(models.UpdateSuggestion.values())),
+        suggestions=suggestions,
     )
 
 


Test patch:
diff --git a/bodhi/tests/server/services/test_updates.py b/bodhi/tests/server/services/test_updates.py
--- a/bodhi/tests/server/services/test_updates.py
+++ b/bodhi/tests/server/services/test_updates.py
@@ -19,6 +19,7 @@
 """This module contains tests for bodhi.server.services.updates."""
 from datetime import datetime, timedelta
 import copy
+import re
 import textwrap
 import time
 
@@ -829,6 +830,11 @@ def test_edit_with_permission(self):
             '/updates/FEDORA-{}-a3bbe1a8f2/edit'.format(datetime.utcnow().year),
             headers={'accept': 'text/html'})
         self.assertIn('Editing an update requires JavaScript', resp)
+        # Make sure that unspecified comes first, as it should be the default.
+        regex = r''
+        for value in ('unspecified', 'reboot', 'logout'):
+            regex = regex + r'name="suggest" value="{}".*'.format(value)
+        self.assertTrue(re.search(regex, resp.body.decode('utf8').replace('\n', ' ')))
 
     def test_edit_without_permission(self):
         """
diff --git a/bodhi/tests/server/views/test_generic.py b/bodhi/tests/server/views/test_generic.py
--- a/bodhi/tests/server/views/test_generic.py
+++ b/bodhi/tests/server/views/test_generic.py
@@ -19,6 +19,7 @@
 
 from datetime import datetime
 import copy
+import re
 
 import mock
 import webtest
@@ -393,6 +394,11 @@ def test_new_update_form(self):
         # Test that a logged in user sees the New Update form
         res = self.app.get('/updates/new')
         self.assertIn('Creating a new update requires JavaScript', res)
+        # Make sure that unspecified comes first, as it should be the default.
+        regex = r''
+        for value in ('unspecified', 'reboot', 'logout'):
+            regex = regex + r'name="suggest" value="{}".*'.format(value)
+        self.assertTrue(re.search(regex, res.body.decode('utf8').replace('\n', ' ')))
 
         # Test that the unlogged in user cannot see the New Update form
         anonymous_settings = copy.copy(self.app_settings)