问题
I'm using the jira Python library for fetching issues from a jira server. In order to reduce the server load and network traffic, I would like to store the search_issues() result locally in serialized form. If most issues would be available locally, I would need to query only these issues which were updated recently.
Unfortunately I ran into a problem, it seems a jira issue is not picklable. I always get the following error when calling dumps() for an issue:
_pickle.PicklingError: Can't pickle <class 'jira.resources.PropertyHolder'>: attribute lookup PropertyHolder on jira.resources failed
I also tried other Python serialization approaches (like marshal, dill, json), but the serialization fails for all of them (this is not too surprising because dill and json seem to rely on pickle).
Any idea how jira issues can be serialized in Python?
回答1:
jira-cache
package worked for me. It can cache an issue list and load it.
https://pypi.org/project/jira-cache/
Example:
def get_issues():
jira = JIRA(auth)
if not cache.exists():
issues = jira.search_issues('project = BLAH')
cached = CachedIssues(issues)
cached.dump(open('issue_cache.json', 'w'))
else:
issues = CachedIssues.load(open('issue_cache.json'))
return issues
回答2:
I got it working.
Changes needed to jira/resources.py
Replace:
top = type(str('PropertyHolder'), (object,), raw)
with
top = PropertyHolder(raw)
and add at the end
class PropertyHolder(object):
def __init__(self, raw):
__bases__ = raw
来源:https://stackoverflow.com/questions/42509348/how-to-serialize-a-jira-issue-object-in-python