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
This commit is contained in:
Andy Botting 2019-07-25 21:40:15 +10:00
parent 40a7d1ad90
commit e1ae0f7143
4 changed files with 5 additions and 5 deletions

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)] = {

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)] = {

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)] = {

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(