Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dictionary keys changed during iteration error seen in utils when using py3.8 #877

Closed
wants to merge 2 commits into from

Conversation

elinnore
Copy link

noticed this error when trying to upload a file in jira while using python 3.8 on MacOS 10.14.6:

Python 3.8.0 (default, Nov 25 2019, 19:38:49) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from jira import JIRA
>>> jira = JIRA(server='http://localhost:8080', basic_auth=('myuser', 'mypass'))
>>> attached = jira.add_attachment(issue='CSTREQ-1', attachment='file_with_text.log')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/myuser/.pyenv/versions/venv/lib/python3.8/site-packages/jira/client.py", line 126, in wrapper
    result = func(*arg_list, **kwargs)
  File "/Users/myuser/.pyenv/versions/venv/lib/python3.8/site-packages/jira/client.py", line 787, in add_attachment
    url, data=m, headers=CaseInsensitiveDict({'content-type': m.content_type, 'X-Atlassian-Token': 'nocheck'}), retry_data=file_stream)
  File "/Users/myuser/.pyenv/versions/venv/lib/python3.8/site-packages/jira/utils/__init__.py", line 41, in __init__
    for key, value in super(CaseInsensitiveDict, self).items():
RuntimeError: dictionary keys changed during iteration

Tested the fix below and there seems to not be any issues. File uploaded fine, no other errors:

>>> attached = jira.add_attachment(issue='CSTREQ-1', attachment='file_with_text.log')
>>> attached
<JIRA Attachment: filename='file_with_text.log', id='10000', mimeType='text/plain'>

if key != key.lower():
self[key.lower()] = value
self.pop(key, None)
# self.itemlist = {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not leave commented out code. Remove it if it's no longer necessary.


# self.itemlist[key.lower()] = value
itemlist = {}
for key, value in super(CaseInsensitiveDict, self).items():
itemlist[key.lower()] = value
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a list of keys to remove and remove them in subsequent for loop?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you. Yes, that would be clearer actually and appears to work fine too:

    def __init__(self, *args, **kw):
        super(CaseInsensitiveDict, self).__init__(*args, **kw)

        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)

Copy link

@lan17 lan17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM to me, but I don't have write access 😢

@stale
Copy link

stale bot commented Dec 26, 2019

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Ticket that is likely to go nowhere and that will be closed soon label Dec 26, 2019
@stale stale bot closed this Jan 9, 2020
@yhuskov
Copy link

yhuskov commented Jan 17, 2020

Can this pull request be reopened? The bug prevents using the add_attachment method with Python 3.8.

@keyroii
Copy link

keyroii commented May 5, 2020

add_attachment method still not working in python 3.8 as of may.

@dbaxa
Copy link
Member

dbaxa commented May 6, 2020

cc @ssbarnea (this seems like a candidate for review & merge).

@ackris
Copy link

ackris commented May 7, 2020

It is still not working. Please find my comment on Issue . Please do a review and release a working candidate

@olologin
Copy link

olologin commented Jun 3, 2020

Oh come on, is it so hard to merge this? It still fails on latest master.

@dbaxa
Copy link
Member

dbaxa commented Jun 3, 2020

@ssbarnea Can we merge this :-) ?

@dbaxa dbaxa reopened this Jun 3, 2020
@AnatoliiSliusarievSecurrency

Can this be merged? It's really a blocker

@wesinator
Copy link
Contributor

seems the issue was already fixed in #895 , just hasn't been released

@dvaerum
Copy link
Contributor

dvaerum commented Jul 29, 2020

seems the issue was already fixed in #895 , just hasn't been released

Can we please have a release when? 🥺 I mean it have been 1/2 year

@ssbarnea ssbarnea closed this Jul 29, 2020
@wesinator
Copy link
Contributor

seems the issue was already fixed in #895 , just hasn't been released

Can we please have a release when? 🥺 I mean it have been 1/2 year

https://github.com/pycontribs/jira/releases/tag/3.0

@CyberTraitsProject
Copy link

we need this change, Why not work on it and release the change?
PLEASE

@russoz
Copy link

russoz commented Aug 23, 2020

Do you want to help? The project 's CI has broken and folks need a hand. That would be a more positive way to collaborate on a volunteer-basis project, instead of thumping your feet making demands.

@sdanelli
Copy link

sdanelli commented Sep 2, 2020

@russoz I think we can help as we are also affected, do you have the details on what is broken to ship this fix?

@russoz
Copy link

russoz commented Sep 5, 2020

@sdanelli I am not a maintainer of the project, but issue #896 is pinned on the Issues tab - the project maintainers are asking for help.

@jd-ssg
Copy link

jd-ssg commented Nov 20, 2020

Could we merge this fix, please ?

@adehad
Copy link
Contributor

adehad commented Jun 26, 2021

No idea if people are still following this, but I've made a PR for the move to requests.structures.CaseInsensitiveDict #1084 which I think also addresses this, I've added a test in which suggests it does, but the test also passes before the change so would be great to confirm with others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Ticket that is likely to go nowhere and that will be closed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.