如何在Python中序列化jira issue对象? [英] How to serialize a jira issue object in Python?

查看:243
本文介绍了如何在Python中序列化jira issue对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jira Python库从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问题吗?

解决方案

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

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?

解决方案

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

这篇关于如何在Python中序列化jira issue对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆