From 2c1098b3afb4f5d7cd1d10eaa722652624e6bb74 Mon Sep 17 00:00:00 2001 From: Nate Johnston Date: Wed, 15 May 2019 19:18:52 -0400 Subject: [PATCH] Use six.viewkeys instead of dict.keys to avoid py2 to py3 problems This change fixes an 'RuntimeError: dictionary changed size during iteration' error that is raised because of different behaviour between python2 and python3. We use the six library to ensure that the behavior is compatible across versions. Change-Id: I0723ae10825e1e2d86789627895e3286d8c97602 Resolves-Bug: #1829304 --- neutron/pecan_wsgi/hooks/policy_enforcement.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/neutron/pecan_wsgi/hooks/policy_enforcement.py b/neutron/pecan_wsgi/hooks/policy_enforcement.py index ff290bc579b..cb92a45e9ae 100644 --- a/neutron/pecan_wsgi/hooks/policy_enforcement.py +++ b/neutron/pecan_wsgi/hooks/policy_enforcement.py @@ -20,6 +20,7 @@ from oslo_log import log as logging from oslo_policy import policy as oslo_policy from oslo_utils import excutils from pecan import hooks +import six import webob from neutron._i18n import _ @@ -121,7 +122,7 @@ class PolicyHook(hooks.PecanHook): original_resources.append(resource_obj) obj = copy.copy(resource_obj) obj.update(item) - obj[const.ATTRIBUTES_TO_UPDATE] = item.keys() + obj[const.ATTRIBUTES_TO_UPDATE] = six.viewkeys(item) # Put back the item in the list so that policies could be # enforced resources_copy.append(obj) @@ -223,7 +224,7 @@ class PolicyHook(hooks.PecanHook): to see them. """ attributes_to_exclude = [] - for attr_name in data.keys(): + for attr_name in six.viewkeys(data): # TODO(amotoki): All attribute maps have tenant_id and # it determines excluded attributes based on tenant_id. # We need to migrate tenant_id to project_id later