From e1ae0f7143ffd379e336950542f54c93998665be Mon Sep 17 00:00:00 2001 From: Andy Botting Date: Thu, 25 Jul 2019 21:40:15 +1000 Subject: [PATCH] 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 --- .../clusters/cluster_templates/workflows/copy.py | 2 +- .../data_processing/clusters/clusters/workflows/update.py | 2 +- .../clusters/nodegroup_templates/workflows/copy.py | 2 +- .../content/data_processing/utils/workflow_helpers.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sahara_dashboard/content/data_processing/clusters/cluster_templates/workflows/copy.py b/sahara_dashboard/content/data_processing/clusters/cluster_templates/workflows/copy.py index e327f770..0425eef6 100644 --- a/sahara_dashboard/content/data_processing/clusters/cluster_templates/workflows/copy.py +++ b/sahara_dashboard/content/data_processing/clusters/cluster_templates/workflows/copy.py @@ -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)] = { diff --git a/sahara_dashboard/content/data_processing/clusters/clusters/workflows/update.py b/sahara_dashboard/content/data_processing/clusters/clusters/workflows/update.py index 490d1f84..f6ede9d1 100644 --- a/sahara_dashboard/content/data_processing/clusters/clusters/workflows/update.py +++ b/sahara_dashboard/content/data_processing/clusters/clusters/workflows/update.py @@ -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)] = { diff --git a/sahara_dashboard/content/data_processing/clusters/nodegroup_templates/workflows/copy.py b/sahara_dashboard/content/data_processing/clusters/nodegroup_templates/workflows/copy.py index 17106cb6..a3bfc5e3 100644 --- a/sahara_dashboard/content/data_processing/clusters/nodegroup_templates/workflows/copy.py +++ b/sahara_dashboard/content/data_processing/clusters/nodegroup_templates/workflows/copy.py @@ -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)] = { diff --git a/sahara_dashboard/content/data_processing/utils/workflow_helpers.py b/sahara_dashboard/content/data_processing/utils/workflow_helpers.py index 6821d8d7..c480845d 100644 --- a/sahara_dashboard/content/data_processing/utils/workflow_helpers.py +++ b/sahara_dashboard/content/data_processing/utils/workflow_helpers.py @@ -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(