From 09e63e8ac9e77d65ad491a03b7a97d83f55fed1d Mon Sep 17 00:00:00 2001 From: Gil8513 Date: Tue, 29 Sep 2020 17:51:00 +0300 Subject: [PATCH] Fix exception with empty resource list (#381) * Fix exception with empty resource list Fix exception that occurs when query returns empty resource list. Iterate over the list items only if it is not None. * Add missing end quote Co-authored-by: Fabian von Feilitzsch --- openshift/dynamic/resource.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/openshift/dynamic/resource.py b/openshift/dynamic/resource.py index 184e1b7a..49e3afd7 100644 --- a/openshift/dynamic/resource.py +++ b/openshift/dynamic/resource.py @@ -276,11 +276,12 @@ def __init__(self, client, instance): kind = instance['kind'] if kind.endswith('List') and 'items' in instance: kind = instance['kind'][:-4] - for item in instance['items']: - if 'apiVersion' not in item: - item['apiVersion'] = instance['apiVersion'] - if 'kind' not in item: - item['kind'] = kind + if instance['items']: + for item in instance['items']: + if 'apiVersion' not in item: + item['apiVersion'] = instance['apiVersion'] + if 'kind' not in item: + item['kind'] = kind self.attributes = self.__deserialize(instance) self.__initialised = True