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

Not able to use JIRA authed instance as pickle serialized object. #259

Closed
mohit1337 opened this issue Sep 20, 2016 · 10 comments
Closed

Not able to use JIRA authed instance as pickle serialized object. #259

mohit1337 opened this issue Sep 20, 2016 · 10 comments
Labels
invalid Not an actual bug.

Comments

@mohit1337
Copy link

I am trying to save a jira authed instance as a pickle serialized object in a Django's request session.

The object is saved successfully and pickled, unpickled succesfully.

However when using the stored instance, it gives error:


Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/var/www/dsm_postman/daakiya/views.py", line 406, in create_jira_bug
    a = jira_instance.issue('TSTH-1082')
  File "/usr/local/lib/python2.7/dist-packages/jira/client.py", line 853, in issue
    issue.find(id, params=params)
  File "/usr/local/lib/python2.7/dist-packages/jira/resources.py", line 168, in find
    self._load(url, params=params)
  File "/usr/local/lib/python2.7/dist-packages/jira/resources.py", line 275, in _load
    r = self._session.get(url, headers=headers, params=params)
  File "/usr/local/lib/python2.7/dist-packages/jira/resilientsession.py", line 149, in get
    return self.__verb('GET', url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/jira/resilientsession.py", line 118, in __verb
    while retry_number <= self.max_retries:
AttributeError: 'ResilientSession' object has no attribute 'max_retries'
@ssbarnea
Copy link
Member

ssbarnea commented Dec 3, 2016

I will close this because I don't see it as a bug in ResilientSession class. It is quite simple: the max_retries attribute is added as part of the __init__ so if you get it missing while calling a method clearly unpickling was not done correctly.

@ssbarnea ssbarnea added the invalid Not an actual bug. label Dec 3, 2016
@ssbarnea ssbarnea closed this as completed Dec 3, 2016
@mohit1337
Copy link
Author

It does not work work even when I try to send jira instance to a multiprocessing apply_async method.
Moreover can you demonstrate the correct way of unpickling? I just followed up usual way with pickle module which works for each and every class instance.

@danielwsutton
Copy link

danielwsutton commented Feb 20, 2017

Hi,
I think this is a bug, i had the same issue,

my workaround was simple though,

   jira_instance = some_method_to_get_jira_object()
    if not hasattr(jira_instance._session, 'max_retries'):
        setattr(jira_instance._session, 'max_retries', 3)
   a = jira_instance.issue(bug_id)

Obviously you will might need to change it up a bit depending to match your naming schemes.

@dwlocks
Copy link

dwlocks commented Sep 28, 2017

I had exactly this problem as well. The above workaround was only a partial fix for me. I also had to setattr for timeout. Perhaps it is related to setting optional values?

@pktiuk
Copy link

pktiuk commented Nov 12, 2020

I have also problems with this Exception.

In order to run my scripts using multiple threads I have to apply:

diff --git a/resilientsession.py b/resilientsession.py
index 334981f..d18bdf9 100644
--- a/resilientsession.py
+++ b/resilientsession.py
@@ -117,15 +117,11 @@ class ResilientSession(Session):
             data = json.dumps(data)

         retry_number = 0
+        if not hasattr(self, 'max_retries'):
+            self.max_retries = 3
         while retry_number <= self.max_retries:
             response = None
             exception = None
             try:
                 method = getattr(super(ResilientSession, self), verb.lower())
+                if not hasattr(self, 'timeout'):
+                    self.timeout = None
                 response = method(url, timeout=self.timeout, **kwargs)
                 if response.status_code == 200:
                     return response

@ssbarnea

Moreover can you demonstrate the correct way of unpickling? I just followed up usual way with pickle module which works for each and every class instance.

Such a demonstration would at least help avoiding this problem.

@jd-ssg
Copy link

jd-ssg commented Nov 20, 2020

I have got the same issue. Thanks pktiuk for your fix. this issue should be reopened !!!!

@pktiuk
Copy link

pktiuk commented Nov 20, 2020

I also think so, in my company many people have this problem and all of us have to apply this fix on official libraries.

@marioaag
Copy link

Looks like the issue still present in the version 3.2.0, is anything that could be done to get the solution proposed by @pktiuk implemented?

@neomafo88
Copy link

bump

@gribas
Copy link

gribas commented May 28, 2024

ResilientSession extends Session which in turn implements the getstate and setstate interface.

When pickle starts serializing ResilientSession it notices the class has the getstate interface and uses that instead
of parsing the whole class. Because the new attributes (timeout,max_retries,max_retry_delay) are not on the getstate list, they are ignored.

The Session uses an internal attribute name list 'attrb' to store the states that should be persisted/serialized.
This list is used by getstate.

We could extend the list to encompass the attributes from ResilientSession. This is what we are using:

diff --git a/jira/resilientsession.py b/jira/resilientsession.py
index f5447f2..f75dc71 100644
--- a/jira/resilientsession.py
+++ b/jira/resilientsession.py
@@ -160,6 +160,7 @@ class ResilientSession(Session):
         self.timeout = timeout
         self.max_retries = max_retries
         self.max_retry_delay = max_retry_delay
+        self.__attrs__.extend(["timeout","max_retries","max_retry_delay"])
         super().__init__()

         # Indicate our preference for JSON to avoid https://bitbucket.org/bspeakmon/jira-python/issue/46 and https://jira.atlassian.com/browse/JRA-38551
	 

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Not an actual bug.
Projects
None yet
Development

No branches or pull requests

9 participants