我正在使用jira Python library从jira服务器获取问题。为了减少服务器负载和网络流量,我想以序列化形式在本地存储search_issues()结果。如果大多数问题都可以在本地获得,我只需要查询最近更新的这些问题。
不幸的是我遇到了一个问题,似乎jira问题是不可挑选的。在为某个问题调用dumps()时,我总是会收到以下错误:
_pickle.PicklingError: Can't pickle <class 'jira.resources.PropertyHolder'>: attribute lookup PropertyHolder on jira.resources failed
我也尝试过其他Python序列化方法(比如marshal,dill,json),但序列化对所有这些都失败了(这并不太令人惊讶,因为dill和json似乎依赖于pickle)。
知道如何在Python中序列化jira问题吗?
答案 0 :(得分:1)
jira-cache
软件包对我有用。它可以缓存并加载问题列表。
https://pypi.org/project/jira-cache/
示例:
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
答案 1 :(得分:0)
我明白了。
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
答案 2 :(得分:0)
这对我有用:
from jira.resources import Issue
# Saving an issue as json in some cache
issue = self.session.search_issues(some_query, maxResults=1)[0]
json = issue.raw
cache.set("my_key", json)
# Getting it from the cache and turning it back into an Issue object
json = cache.get("my_key")
issue = Issue(options=None, session=self.session, raw=json)