Closed ivanst0 closed 4 years ago
Thanks for the report! I made a PR for the fix. You also made me realize that I should use Python 3 when I can, so I use timezone
is I can and use _FixedOffset only on Py 2.7.
Thanks again for the detailled report! You made the unittests actually :)
Will ship part of 0.6.15 this week.
thanks again for the report :)
Repro
Output (msrest 0.6.13)
Output (msrest 0.6.14)
Details
This regression was introduced in https://github.com/Azure/msrest-for-python/pull/201.
After that change, in the example above
timedate1
is not picklable becausetimedate1.tzinfo
contains an instance of_FixedOffset
which is not picklable itself.pickle.dumps(datetime1)
invokestimedate1.tzinfo.__reduce__()
._FixedOffset
class doesn't define the__reduce__()
method and the implementation from its parent class is used.tzinfo.__reduce__()
assumes that the class implements__getinitargs__()
method. This is true fordatetime.timezone
, but not for_FixedOffset
. Eventually,pickle.loads(pickled)
tries to call_FixedOffset.__init__()
without the requiredoffset
argument, resulting in aTypeError
.In practice the issue happens when trying to pickle/unpickle any object containing a
datetime
generated byDeserializer.deserialize_rfc()
, e.g. withmultiprocessing
.Potential solutions
_FixedOffset.__getinitargs__()
._FixedOffset.__reduce__()
._FixedOffset
use the default implementation of__reduce__()
, instead of one inherited fromdatetime.tzinfo
:__reduce__ = object.__reduce__
Once Python 2.7 compatibility is no longer required,
datetime.timezone
can be used instead of_FixedOffset
.