Browse Source

Fix filter() usage for Py 3

The use of filter() within the codebase expected the output to be
an interator, but the filter function in Python 3 now returns a
lazy loading generator and resulted in stack traces.

This commit replaces the use of filter() (+ lambdas) with more
readable list comprehension to be compatible with Python 2 and 3.

Change-Id: I56af1dc1f6648ec334f901cb59893240b0125031
changes/50/679450/1
Andy Botting 1 month ago
parent
commit
5f297e0079

+ 1
- 1
sahara_dashboard/content/data_processing/clusters/cluster_templates/workflows/copy.py View File

@@ -120,7 +120,7 @@ class CopyClusterTemplate(create_flow.ConfigureClusterTemplate):
120 120
         values = dict()
121 121
         for i, choice in enumerate(choices):
122 122
             share_id = choice[0]
123
-            s = filter(lambda s: s['id'] == share_id, self.template.shares)
123
+            s = [s for s in self.template.shares if s['id'] == share_id]
124 124
             if len(s) > 0:
125 125
                 path = s[0]["path"] if "path" in s[0] else ""
126 126
                 values["share_id_{0}".format(i)] = {

+ 1
- 1
sahara_dashboard/content/data_processing/clusters/clusters/workflows/update.py View File

@@ -53,7 +53,7 @@ class SelectSharesAction(workflows.Action):
53 53
         choices = share_field.choices
54 54
         for i, choice in enumerate(choices):
55 55
             share_id = choice[0]
56
-            s = filter(lambda s: s['id'] == share_id, cluster_shares)
56
+            s = [s for s in cluster_shares if s['id'] == share_id]
57 57
             if len(s) > 0:
58 58
                 path = s[0]["path"] if "path" in s[0] else ""
59 59
                 values["share_id_{0}".format(i)] = {

+ 1
- 1
sahara_dashboard/content/data_processing/clusters/nodegroup_templates/workflows/copy.py View File

@@ -130,7 +130,7 @@ class CopyNodegroupTemplate(create_flow.ConfigureNodegroupTemplate):
130 130
         choices = share_fields['shares'].choices
131 131
         for i, choice in enumerate(choices):
132 132
             share_id = choice[0]
133
-            s = filter(lambda s: s['id'] == share_id, self.template.shares)
133
+            s = [s for s in self.template.shares if s['id'] == share_id]
134 134
             if len(s) > 0:
135 135
                 path = s[0].get('path', '')
136 136
                 values["share_id_{0}".format(i)] = {

+ 2
- 2
sahara_dashboard/content/data_processing/utils/workflow_helpers.py View File

@@ -251,8 +251,8 @@ def populate_image_choices(self, request, context, empty_choice=False):
251 251
 
252 252
 class PluginAndVersionMixin(object):
253 253
     def _generate_plugin_version_fields(self, sahara):
254
-        plugins = sahara.plugins.list()
255
-        plugins = filter(is_plugin_not_hidden_for_user, plugins)
254
+        plugins = [p for p in sahara.plugins.list()
255
+                   if is_plugin_not_hidden_for_user(p)]
256 256
         plugin_choices = [(plugin.name, plugin.title) for plugin in plugins]
257 257
 
258 258
         self.fields["plugin_name"] = forms.ChoiceField(

Loading…
Cancel
Save