prayagverma / gdata-python-client

Automatically exported from code.google.com/p/gdata-python-client
1 stars 0 forks source link

gdata.photos.GooglePhotosException is not picklable #648

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When running the attached unpicklable_googlephotosexception.py file I get:
Traceback (most recent call last):
  File ".\unpicklable_googlephotosexception.py", line 10, in <module>
    unpickled = pickle.loads(pickled)
  File "C:\Python26\lib\pickle.py", line 1374, in loads
    return Unpickler(file).load()
  File "C:\Python26\lib\pickle.py", line 858, in load
    dispatch[key](self)
  File "C:\Python26\lib\pickle.py", line 1133, in load_reduce
    value = func(*args)
TypeError: __init__() takes exactly 2 arguments (4 given)

This is because of the way GooglePhotosException.__init__ interacts with 
self.args. Python's Exception has self.args which it sets to the packed 
arguments that Exception.__init__ was called with. But GooglePhotosException 
takes 1 argument (reason) and sets self.args to a list of 3 elements based on 
that. While unpickling, GooglePhotosException.__init__ is called with the 
unpacked previously pickled self.args, therefore with 3 arguments (+ self = 4) 
and it only accepts 2 (reason + self).

With the attached patch, unpicklable_googlephotosexception.py runs successfully.

Having exceptions picklable is especially important when using the 
multiprocessing module since it pickles exceptions to transfer them across 
processes. When running gdata code in a multiprocessing child which raises a 
GooglePhotosException, the parent process gets the above TypeError instead of 
GooglePhotosException.

Original issue reported on code.google.com by c.ia...@cebra.eu on 21 Nov 2012 at 2:15

Attachments:

GoogleCodeExporter commented 9 years ago
This is great, but please use the upload-diffs.py script to make a code review.

Original comment by afs...@google.com on 21 Nov 2012 at 2:48

GoogleCodeExporter commented 9 years ago
Patch uploaded to http://codereview.appspot.com/6844072

Original comment by c.ia...@cebra.eu on 22 Nov 2012 at 9:59