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

Method add_attachment() error with python 3.8 -- RuntimeError: dictionary keys changed during iteration #890

Closed
dannylui opened this issue Jan 9, 2020 · 11 comments · Fixed by #895

Comments

@dannylui
Copy link

dannylui commented Jan 9, 2020

Describe the bug
When calling the add_attachment method in python 3.8, we hit RuntimeError: dictionary keys changed during iteration. We verified that rolling back to python 3.7, the same code works as expected.

To Reproduce
Steps to reproduce the behavior:

jira.add_attachment(issue=issue, attachment='/some/path/attachment.txt')
  1. No additional steps.

Expected behavior
File attachement uploaded to JIRA and attached to issue.

Stack Trace

Traceback (most recent call last):
  File "test_attachments.py", line 302, in <module>
    main()
  File "test_attachments.py", line 298, in main
    test.attachments(args)
  File "test_attachments.py", line 207, in migrate
    self._jira.add_attachment(issue=issue, attachment=attachment_path)
  File "C:\Users\dlui\workspace\test_attachments\venv\lib\site-packages\jira\client.py", line 126, in wrapper
    result = func(*arg_list, **kwargs)
  File "C:\Users\dlui\workspace\test_attachments\venv\lib\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 "C:\Users\dlui\workspace\test_attachments\venv\lib\site-packages\jira\utils\__init__.py", line 41, in __init__
    for key, value in super(CaseInsensitiveDict, self).items():
RuntimeError: dictionary keys changed during iteration```

Version Information
Python Interpreter: 3.8
jira-python: 2.0.0
OS: Windows 10
IPython (Optional):
Other Dependencies:

Additional context
None

@earshinov
Copy link

earshinov commented Jan 20, 2020

FYI, this error comes from this change introduced in Python 3.8:
https://bugs.python.org/issue36452

It is not mentioned in the main changelog for Python 3.8 (https://docs.python.org/3/whatsnew/3.8.html), but IS mentioned in the "full" one (https://docs.python.org/3/whatsnew/changelog.html#changelog).

japz pushed a commit to japz/jira that referenced this issue Jan 24, 2020
Python 3.8 will thrown an exception if a dict changes while iterating over it,
copy it first.

Fix pycontribs#890
ssbarnea pushed a commit that referenced this issue Mar 31, 2020
Python 3.8 will thrown an exception if a dict changes while iterating over it,
copy it first.

Fix #890
@ackris
Copy link

ackris commented May 7, 2020

Dear JIRA Python API team,

This issue is still surfacing despite the merge.

My system's python version is 3.8.2 & OS is Win10.

PFB the stack trace.

Traceback (most recent call last):
  File "jiratxn.py", line 88, in <module>
    jiratxn()
  File "jiratxn.py", line 81, in jiratxn
    jira.add_attachment(issue=issue, attachment=f)
  File "C:\Users\Kris\AppData\Local\Programs\Python\Python38-32\lib\site-packages\jira\client.py", line 126, in wrapper
    result = func(*arg_list, **kwargs)
  File "C:\Users\Kris\AppData\Local\Programs\Python\Python38-32\lib\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 "C:\Users\Kris\AppData\Local\Programs\Python\Python38-32\lib\site-packages\jira\utils\__init__.py", line 41, in __init__
    for key, value in super(CaseInsensitiveDict, self).items():
RuntimeError: dictionary keys changed during iteration

Here is my code snippet

for f in listdir(args.reports):
                    try:
                        if f.endswith('.json'):
                            with open(join(args.reports, f), 'rb') as f:
                                jira.add_attachment(issue=issue, attachment=f)
                                print('Successfully added attachment to the '+issue+'')
                    except FileNotFoundError:
                        raise FileNotFoundError('Could not the JSON file you are looking for. Are you sure the path/filename is correct?')

I don't want to downgrade python version.

Regards
Kris

@wesinator
Copy link
Contributor

@ssbarnea can you do a new release with this fix ?

Thanks,

mrbschroeder pushed a commit to diurnate/jira that referenced this issue Aug 25, 2020
Python 3.8 will thrown an exception if a dict changes while iterating over it,
copy it first.

Fix pycontribs#890
@amaistrenko-od-ua
Copy link

Dear JIRA Python API team,

I got same issue.
Python version: 3.8.6.
And Jenkins (Debian) as a system.

Exception:
File "/var/jenkins_home/.local/share/virtualenvs/app-J2ca32bp/lib/python3.8/site-packages/jira/client.py", line 126, in wrapper
result = func(*arg_list, **kwargs)
File "/var/jenkins_home/.local/share/virtualenvs/app-J2ca32bp/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 "/var/jenkins_home/.local/share/virtualenvs/app-J2ca32bp/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

Thanks.

@wesinator
Copy link
Contributor

This is fixed in 3.0 of this package - https://github.com/pycontribs/jira/releases/tag/3.0

@amaistrenko-od-ua
Copy link

Manually update lib to jira-3.0a1 and jira-3.0a2 from pip, but issue still reproduced.

@srinubalsu
Copy link

srinubalsu commented Nov 18, 2020 via email

@dblanchette
Copy link
Contributor

It works when using the version 3.0 from GitHub

In poetry's syntax:
jira = { git = "https://github.com/pycontribs/jira.git", tag = "3.0" }

I don't know why it is still not released to pypi though.

@medic8601
Copy link

Hello all,

Still seeing the 2.0 release in pypi as the latest. And the issue still arises with python 3.9. Any ETA on when the 3.0 release will push to pypi?

@netllama
Copy link

Adding my name to the list of 'me too' since upgrading to python-3.8.x.

I don't understand why this ticket is closed when there's no fix available yet?

@abrs907
Copy link

abrs907 commented Aug 12, 2021

Adding attachments with version 3.0.1 with Python 3.9.5 is working.
pip install jira==3.0.1

svermeulen pushed a commit to svermeulen/jira that referenced this issue Oct 31, 2021
Python 3.8 will thrown an exception if a dict changes while iterating over it,
copy it first.

Fix pycontribs#890
shng5175 pushed a commit to shng5175/prplOS that referenced this issue Apr 5, 2022
Seems like Python 3.8 introduced change, which is causing issues in
python-jira library when adding attachments:

 File "scripts/gitlab/prpl-jira.py", line 136, in build_failure
     self.jira.add_attachment(
   File "/usr/local/lib/python3.8/site-packages/jira/client.py", line 126, in wrapper
     result = func(*arg_list, **kwargs)
   File "/usr/local/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 "/usr/local/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

Until it's fixed upstream, workaround it by using Python 3.7, otherwise
we would need to maintain our own fork of jira-python library.

Ref: https://bugs.python.org/issue36452
Ref: pycontribs/jira#890
Signed-off-by: Petr Štetiar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants