def _convert_lookups_to_id(self, mapping, lookup_keys):
    for lookup_key in lookup_keys:
        lookup_dict = mapping['lookups'][lookup_key]
        model = self.models[mapping['table']]
        lookup_mapping = self._get_mapping_for_table(lookup_dict['table'])
        lookup_model = self.models[lookup_mapping['sf_id_table']]
        key_field = get_lookup_key_field(lookup_dict, lookup_key)
        key_attr = getattr(model, key_field)
        try:
            self.session.query(model).filter(key_attr.isnot(None), (key_attr == lookup_model.sf_id)).update({key_attr: lookup_model.id}, synchronize_session=False)
        except NotImplementedError:
            mappings = []
            for (row, lookup_id) in self.session.query(model, lookup_model.id).join(lookup_model, (key_attr == lookup_model.sf_id)):
                mappings.append({'id': row.id, key_field: lookup_id})
            self.session.bulk_update_mappings(model, mappings)
    self.session.commit()
def _convert_lookups_to_id(self, mapping, lookup_keys):
    for lookup_key in lookup_keys:
        lookup_dict = mapping['lookups'][lookup_key]
        model = self.models[mapping['table']]
        lookup_mapping = self._get_mapping_for_table(lookup_dict['table'])
        lookup_model = self.models[lookup_mapping['sf_id_table']]
        key_field = get_lookup_key_field(lookup_dict, lookup_key)
        key_attr = getattr(model, key_field)
        try:
            self.session.query(model).filter(key_attr.isnot(None), (key_attr == lookup_model.sf_id)).update({key_attr: lookup_model.id}, synchronize_session=False)
        except NotImplementedError:
            mappings = []
            for (row, lookup_id) in self.session.query(model, lookup_model.id).join(lookup_model, (key_attr == lookup_model.sf_id)):
                mappings.append({'id': row.id, key_field: lookup_id})
            self.session.bulk_update_mappings(model, mappings)
    self.session.commit()