From e5f00207f7ca4ab1fab1f733b2860b242b393035 Mon Sep 17 00:00:00 2001 From: Zhao Chao Date: Thu, 15 Mar 2018 21:39:10 +0800 Subject: [PATCH] Use for loop instead of map to modify iterables Previously we use map() to apply changes to every item in a iterable object, but this is not a proper usage. And in Python3, map() will return a map iterator object, changes will not be applied immediately, as we're not iterating the map object, changes will never be applied. Changing to for loop instead fixes. Partial-Bug: #1755413 Change-Id: Iebbfaca67cda72300636e51686bac3b1513b127d Signed-off-by: Zhao Chao --- trove_dashboard/content/database_clusters/views.py | 3 ++- trove_dashboard/content/databases/tabs.py | 4 ++-- trove_dashboard/content/databases/views.py | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/trove_dashboard/content/database_clusters/views.py b/trove_dashboard/content/database_clusters/views.py index 8a27774..662f09a 100644 --- a/trove_dashboard/content/database_clusters/views.py +++ b/trove_dashboard/content/database_clusters/views.py @@ -86,7 +86,8 @@ class IndexView(horizon_tables.DataTableView): msg = _('Unable to retrieve database clusters.') exceptions.handle(self.request, msg) - map(self._extra_data, clusters) + for cluster in clusters: + self._extra_data(cluster) return clusters diff --git a/trove_dashboard/content/databases/tabs.py b/trove_dashboard/content/databases/tabs.py index 18445e1..bc59bdb 100644 --- a/trove_dashboard/content/databases/tabs.py +++ b/trove_dashboard/content/databases/tabs.py @@ -113,8 +113,8 @@ class DatabaseTab(tabs.TableTab): instance = self.tab_group.kwargs['instance'] try: data = api.trove.database_list(self.request, instance.id) - add_instance = lambda d: setattr(d, 'instance', instance) - map(add_instance, data) + for database in data: + setattr(database, 'instance', instance) except Exception: msg = _('Unable to get databases data.') exceptions.handle(self.request, msg) diff --git a/trove_dashboard/content/databases/views.py b/trove_dashboard/content/databases/views.py index 4e3bf04..8f68879 100644 --- a/trove_dashboard/content/databases/views.py +++ b/trove_dashboard/content/databases/views.py @@ -80,7 +80,8 @@ class IndexView(horizon_tables.DataTableView): instances = [] msg = _('Unable to retrieve database instances.') exceptions.handle(self.request, msg) - map(self._extra_data, instances) + for instance in instances: + self._extra_data(instance) return instances