Open LeanidN opened 7 years ago
During my testing .rename() started to fail as well. I think AD operation are not fast enough for update dn: self.__set_gc_adsi_obj() it was failing on ladt line: self._gc_adsi_obj = self.adsi_provider.GetObject('', path) It still had old path.
So I added newdn assignment to self._ADObject__distinguished_name in both functions .rename() and .move()
new_dn = ','.join((self.prefixed_cn, new_ou_object.dn))
time.sleep(.5)
**self._ADObject__distinguished_name=new_dn**
self.__ads_path = pyadutils.generate_ads_path(new_dn, self.default_ldap_protocol,
self.default_ldap_server, self.default_ldap_port)
self.__set_adsi_obj()
self.__set_gc_adsi_obj()
self.__distinguished_name = self.get_attribute('distinguishedName', False)
It seems to fix an issue.
sorry messed up formatting but line I added: self._ADObject__distinguished_name=new_dn
This time I definitely hit the bug or limitation. This code gives exception: user.rename("MyUser-test",set_sAMAccountName=False) user.move(pyad.adcontainer.ADContainer.from_dn("ou=Test,dc=my,dc=ca"))
Problem is rename does not change dn attribute. Looking in Debugger after executing .rename I see that next attribute still have old DN names: _ADObject__distinguished_name dn
And next attributes have proper new name: _ADObjectads_path _ADObjectdistinguishedName adsPath prefixed_cn
As result .move (or any other operation) will try to use old DN that is no longer correct. I just wonder if just by updating '_ADObject__distinguished_name' and 'dn' it should be fixed or I need to reinitialize user object?