Merge branch 'main' into avm99963-monorail

Merged commit 34d8229ae2b51fb1a15bd208e6fe6185c94f6266

GitOrigin-RevId: 7ee0917f93a577e475f8e09526dd144d245593f4
diff --git a/services/features_svc.py b/services/features_svc.py
index 471a513..b2edce3 100644
--- a/services/features_svc.py
+++ b/services/features_svc.py
@@ -1,7 +1,6 @@
-# Copyright 2016 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file or at
-# https://developers.google.com/open-source/licenses/bsd
+# Copyright 2016 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
 
 """A class that provides persistence for Monorail's additional features.
 
@@ -25,7 +24,7 @@
 from framework import framework_bizobj
 from framework import framework_constants
 from framework import sql
-from proto import features_pb2
+from mrproto import features_pb2
 from services import caches
 from services import config_svc
 from tracker import tracker_bizobj
@@ -109,12 +108,12 @@
                                          adder_id=adder_id , date_added=added,
                                          note=note))
       else:
-        logging.warn('hotlist %d not found', hotlist_id)
+        logging.warning('hotlist %d not found', hotlist_id)
 
     for (hotlist_id, user_id, role_name) in role_rows:
       hotlist = hotlist_dict.get(hotlist_id)
       if not hotlist:
-        logging.warn('hotlist %d not found', hotlist_id)
+        logging.warning('hotlist %d not found', hotlist_id)
       elif role_name == 'owner':
         hotlist.owner_ids.append(user_id)
       elif role_name == 'editor':
@@ -199,9 +198,9 @@
     for (hotlist_id, user_id) in owner_rows:
       found_owner_id = hotlist_to_owner_id.get(hotlist_id)
       if found_owner_id:
-        logging.warn(
-            'hotlist %d has more than one owner: %d, %d',
-            hotlist_id, user_id, found_owner_id)
+        logging.warning(
+            'hotlist %d has more than one owner: %d, %d', hotlist_id, user_id,
+            found_owner_id)
       hotlist_to_owner_id[hotlist_id] = user_id
 
     # Note: hotlist_rows hotlists found in the owner_rows that have names
@@ -230,13 +229,13 @@
 
     role_rows = self.features_service.hotlist2user_tbl.Select(
         cnxn, cols=['hotlist_id', 'user_id'],
-        user_id=wanted_names_for_owner.keys(), role_name='owner')
+        user_id=sorted(wanted_names_for_owner.keys()), role_name='owner')
 
     hotlist_ids = [row[0] for row in role_rows]
     hotlist_rows = self.features_service.hotlist_tbl.Select(
         cnxn, cols=['id', 'name'], id=hotlist_ids, is_deleted=False,
         where=[('LOWER(name) IN (%s)' % sql.PlaceHolders(hotlist_names_set),
-                [name.lower() for name in hotlist_names_set])])
+                [name.lower() for name in sorted(hotlist_names_set)])])
 
     return self._DeserializeHotlistIDs(
         hotlist_rows, role_rows, wanted_names_for_owner)
@@ -685,11 +684,10 @@
         if any(email in predicate for email in emails):
           deleted_rows.append(rule_row)
           continue
-        if any(
-            (('add_notify:%s' % email) in consequence or
-             ('add_cc_id:%s' % user_id) in consequence or
-             ('default_owner_id:%s' % user_id) in consequence)
-            for email, user_id in user_ids_by_email.iteritems()):
+        if any((('add_notify:%s' % email) in consequence or
+                ('add_cc_id:%s' % user_id) in consequence or
+                ('default_owner_id:%s' % user_id) in consequence)
+               for email, user_id in user_ids_by_email.items()):
           deleted_rows.append(rule_row)
           continue
 
@@ -799,8 +797,8 @@
 
     self.hotlist_2lc.InvalidateKeys(cnxn, [hotlist_id])
     if not hotlist.owner_ids:  # Should never happen.
-      logging.warn('Modifying unowned Hotlist: id:%r, name:%r',
-        hotlist_id, hotlist.name)
+      logging.warning(
+          'Modifying unowned Hotlist: id:%r, name:%r', hotlist_id, hotlist.name)
     elif hotlist.name:
       self.hotlist_id_2lc.InvalidateKeys(
           cnxn, [(hotlist.name.lower(), owner_id) for
@@ -900,8 +898,10 @@
       affected_issue_ids.update(remove_issue_ids)
       self.hotlist2issue_tbl.Delete(
           cnxn, hotlist_id=hotlist_id, issue_id=remove_issue_ids, commit=False)
-      all_hotlist_items = filter(
-          lambda item: item.issue_id not in remove_issue_ids, all_hotlist_items)
+      all_hotlist_items = list(
+          filter(
+              lambda item: item.issue_id not in remove_issue_ids,
+              all_hotlist_items))
 
     if updated_items:
       updated_issue_ids = [item.issue_id for item in updated_items]
@@ -916,9 +916,10 @@
                 item.date_added, item.note))
       self.hotlist2issue_tbl.InsertRows(
           cnxn, cols=HOTLIST2ISSUE_COLS, row_values=insert_rows, commit=False)
-      all_hotlist_items = filter(
-          lambda item: item.issue_id not in updated_issue_ids,
-          all_hotlist_items)
+      all_hotlist_items = list(
+          filter(
+              lambda item: item.issue_id not in updated_issue_ids,
+              all_hotlist_items))
       all_hotlist_items.extend(updated_items)
 
     if commit:
@@ -1270,8 +1271,9 @@
     self.hotlist_user_to_ids.InvalidateKeys(cnxn, hotlist.owner_ids)
     self.hotlist_user_to_ids.InvalidateKeys(cnxn, hotlist.editor_ids)
     if not hotlist.owner_ids:  # Should never happen.
-      logging.warn('Soft-deleting unowned Hotlist: id:%r, name:%r',
-        hotlist_id, hotlist.name)
+      logging.warning(
+          'Soft-deleting unowned Hotlist: id:%r, name:%r', hotlist_id,
+          hotlist.name)
     elif hotlist.name:
       self.hotlist_id_2lc.InvalidateKeys(
           cnxn, [(hotlist.name.lower(), owner_id) for