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
tags/10.0.1^0
Andy Botting Jeremy Freudberg 10 months ago
parent
commit
5f297e0079
4 changed files with 5 additions and 5 deletions
  1. +1
    -1
      sahara_dashboard/content/data_processing/clusters/cluster_templates/workflows/copy.py
  2. +1
    -1
      sahara_dashboard/content/data_processing/clusters/clusters/workflows/update.py
  3. +1
    -1
      sahara_dashboard/content/data_processing/clusters/nodegroup_templates/workflows/copy.py
  4. +2
    -2
      sahara_dashboard/content/data_processing/utils/workflow_helpers.py

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

@@ -120,7 +120,7 @@ class CopyClusterTemplate(create_flow.ConfigureClusterTemplate):
values = dict()
for i, choice in enumerate(choices):
share_id = choice[0]
s = filter(lambda s: s['id'] == share_id, self.template.shares)
s = [s for s in self.template.shares if s['id'] == share_id]
if len(s) > 0:
path = s[0]["path"] if "path" in s[0] else ""
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):
choices = share_field.choices
for i, choice in enumerate(choices):
share_id = choice[0]
s = filter(lambda s: s['id'] == share_id, cluster_shares)
s = [s for s in cluster_shares if s['id'] == share_id]
if len(s) > 0:
path = s[0]["path"] if "path" in s[0] else ""
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):
choices = share_fields['shares'].choices
for i, choice in enumerate(choices):
share_id = choice[0]
s = filter(lambda s: s['id'] == share_id, self.template.shares)
s = [s for s in self.template.shares if s['id'] == share_id]
if len(s) > 0:
path = s[0].get('path', '')
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):

class PluginAndVersionMixin(object):
def _generate_plugin_version_fields(self, sahara):
plugins = sahara.plugins.list()
plugins = filter(is_plugin_not_hidden_for_user, plugins)
plugins = [p for p in sahara.plugins.list()
if is_plugin_not_hidden_for_user(p)]
plugin_choices = [(plugin.name, plugin.title) for plugin in plugins]

self.fields["plugin_name"] = forms.ChoiceField(


Loading…
Cancel
Save