From 40679dc464bf39ecdc8419f055a240ac7ec31f07 Mon Sep 17 00:00:00 2001 From: Enzo Candotti Date: Wed, 7 Dec 2022 12:09:14 -0300 Subject: [PATCH] Fix 'dictionary changed size during iteration' The Python "RuntimeError: dictionary changed size during iteration" has been seen on some points, e.g. when creating a strategy. It occurs when the size of a dictionary is changed during iterating over it. To fix this error is needed to add a '.copy()' method to create a shallow copy of the dictionary. Test Plan: PASS: Apply these changes and create a strategy. Verify the strategy is being created successfully. Same test has been done for other sections. Closes-Bug: 1999069 Signed-off-by: Enzo Candotti Change-Id: I3f6dc0e27547d6439a2d14e9ba8ee6dd4f68e8be --- .../dashboards/admin/system_config/forms.py | 4 ++-- .../dashboards/dc_admin/dc_orchestration/forms.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/system_config/forms.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/system_config/forms.py index 58014772..8ff05655 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/system_config/forms.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/system_config/forms.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2020 Wind River Systems, Inc. +# Copyright (c) 2013-2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -726,7 +726,7 @@ class UpdateiStoragePools(forms.SelfHandlingForm): STORAGE_VALUES['object_pool_gib'] = \ str(storage_config._object_pool_gib) - for key in data.keys(): + for key in data.copy().keys(): data[key] = str(data[key]) LOG.info("initial send_to_sysinv=%s", send_to_sysinv) diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/dc_admin/dc_orchestration/forms.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/dc_admin/dc_orchestration/forms.py index f17bce1f..70de1f5b 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/dc_admin/dc_orchestration/forms.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/dc_admin/dc_orchestration/forms.py @@ -222,7 +222,7 @@ class CreateCloudStrategyForm(forms.SelfHandlingForm): def handle(self, request, data): try: # convert keys to use dashes - for k in data.keys(): + for k in data.copy().keys(): if 'subcloud_group' in k or 'cloud_name' in k: continue elif '_' in k: @@ -340,7 +340,7 @@ class CreateCloudPatchConfigForm(forms.SelfHandlingForm): def handle(self, request, data): try: - for k in data.keys(): + for k in data.copy().keys(): if '_' in k: data[k.replace('_', '-')] = data[k] del data[k]