From d02cbe1e8a6de92e753cad5bb9cb987a836c7ad1 Mon Sep 17 00:00:00 2001 From: niculice Date: Tue, 26 Nov 2019 00:44:44 +0200 Subject: [PATCH 1/2] fix dictionary keys changed during iteration error seen in CaseInsensitiveDict class in py3.8 --- jira/utils/__init__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/jira/utils/__init__.py b/jira/utils/__init__.py index 0de4b91b8..b9a3d2226 100644 --- a/jira/utils/__init__.py +++ b/jira/utils/__init__.py @@ -36,13 +36,18 @@ class CaseInsensitiveDict(dict): def __init__(self, *args, **kw): super(CaseInsensitiveDict, self).__init__(*args, **kw) - self.itemlist = {} - for key, value in super(CaseInsensitiveDict, self).items(): - if key != key.lower(): - self[key.lower()] = value - self.pop(key, None) +# self.itemlist = {} +# for key, value in super(CaseInsensitiveDict, self).items(): +# if key != key.lower(): +# self[key.lower()] = value +# self.pop(key, None) # self.itemlist[key.lower()] = value + itemlist = {} + for key, value in super(CaseInsensitiveDict, self).items(): + itemlist[key.lower()] = value + self = itemlist + def __setitem__(self, key, value): """Overwrite [] implementation.""" From 9caed80a031421182102d64ea0d4645947fd2e64 Mon Sep 17 00:00:00 2001 From: niculice Date: Tue, 26 Nov 2019 20:05:23 +0200 Subject: [PATCH 2/2] create separate list of upper keys to remove from dict --- jira/utils/__init__.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/jira/utils/__init__.py b/jira/utils/__init__.py index b9a3d2226..a3b94997b 100644 --- a/jira/utils/__init__.py +++ b/jira/utils/__init__.py @@ -36,18 +36,14 @@ class CaseInsensitiveDict(dict): def __init__(self, *args, **kw): super(CaseInsensitiveDict, self).__init__(*args, **kw) -# self.itemlist = {} -# for key, value in super(CaseInsensitiveDict, self).items(): -# if key != key.lower(): -# self[key.lower()] = value -# self.pop(key, None) - - # self.itemlist[key.lower()] = value - itemlist = {} - for key, value in super(CaseInsensitiveDict, self).items(): - itemlist[key.lower()] = value - self = itemlist - + upper_keys_list = [] + for key in super(CaseInsensitiveDict, self).keys(): + if key != key.lower(): + upper_keys_list.append(key) + + for upper_key in upper_keys_list: + self[upper_key.lower()] = self[upper_key] + self.pop(upper_key, None) def __setitem__(self, key, value): """Overwrite [] implementation."""