Skip to content

Pickling an unconnected Reconnect client fails #293

Open
@teruokun

Description

@teruokun

Issue description:
Pickling and unpickling of an unconnected ReconnectLdapObject fails because _last_bind is not set.

Steps to reproduce: Create a new ReconnectLdapObject and attempt to pickle it

Operating system: OSX and Linux confirmed, likely applies to all OS

Python version: Confirmed in 2.7, 3.4, and 3.6

python-ldap version: 3.2.0

Patch:

--- a/Lib/ldap/ldapobject.py
+++ b/Lib/ldap/ldapobject.py
@@ -1116,7 +1116,7 @@ class ReconnectLDAPObject(SimpleLDAPObject):
         for k,v in self.__dict__.items()
         if k not in self.__transient_attrs__
     }
-    state['_last_bind'] = self._last_bind[0].__name__, self._last_bind[1], self._last_bind[2]
+    state['_last_bind'] = (self._last_bind[0].__name__, self._last_bind[1], self._last_bind[2]) if self._last_bind is not None else None
     return state

   def __setstate__(self,d):
@@ -1127,7 +1127,8 @@ class ReconnectLDAPObject(SimpleLDAPObject):
     else:
         d.setdefault('bytes_strictness', 'warn')
     self.__dict__.update(d)
-    self._last_bind = getattr(SimpleLDAPObject, self._last_bind[0]), self._last_bind[1], self._last_bind[2]
+    if self._last_bind is not None:
+        self._last_bind = getattr(SimpleLDAPObject, self._last_bind[0]), self._last_bind[1], self._last_bind[2]
     self._ldap_object_lock = self._ldap_lock()
     self._reconnect_lock = ldap.LDAPLock(desc='reconnect lock within %s' % (repr(self)))
     # XXX cannot pickle file, use default trace file

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions