[ldapfeed] extid and cwuri aren't the same thing
authorJulien Cristau <julien.cristau@logilab.fr>
Mon, 04 Jan 2016 10:36:57 +0100
changeset 11045 615163b17558
parent 11044 00c5ee272a6d
child 11046 b8180114ecde
[ldapfeed] extid and cwuri aren't the same thing Historically, we used a ldap://... URI as cwuri attribute, not just the dn. The extid field, OTOH, was always the dn. So when initializing our dict of known entities from an ldap source, look at existing extids, not cwuris, to avoid importing already-existing users (and violated unicity constraints).
sobjects/ldapparser.py
--- a/sobjects/ldapparser.py	Wed Dec 23 15:44:28 2015 +0100
+++ b/sobjects/ldapparser.py	Mon Jan 04 10:36:57 2016 +0100
@@ -120,8 +120,8 @@
     def build_importer(self, raise_on_error):
         """Instantiate and configure an importer"""
         etypes = ('CWUser', 'EmailAddress', 'CWGroup')
-        extid2eid = dict((x.encode('ascii'), y) for x, y in
-                importer.cwuri2eid(self._cw, etypes, source_eid=self.source.eid).items())
+        extid2eid = dict((self.source.decode_extid(x), y) for x, y in
+                self._cw.system_sql('select extid, eid from entities where asource = %(s)s', {'s': self.source.uri}))
         existing_relations = {}
         for rtype in ('in_group', 'use_email', 'owned_by'):
             rql = 'Any S,O WHERE S {} O, S cw_source SO, SO eid %(s)s'.format(rtype)