def sync_ldap_groups(self, ldap_groups):
        """
        Synchronize LDAP groups with local group database.
        """
        attributes = getattr(settings, 'LDAP_SYNC_GROUP_ATTRIBUTES', None)
        groupname_field = 'name'

        if attributes.values() not in groupname_field:
            error_msg = ("LDAP_SYNC_GROUP_ATTRIBUTES must contain the "
                         "group name field '%s'" % groupname_field)
            raise ImproperlyConfigured(error_msg)

        for cname, attrs in ldap_groups:
            # In some cases with AD, attrs is a list instead of a
            # dict; these are not valid groups, so skip them
            try:
                items = attrs.items()
            except AttributeError:
                continue

            # Extract user data from LDAP response
            group_attr = {}
            for name, attr in items:
                group_attr[attributes[name]] = attr[0].decode('utf-8')

            try:
                groupname = group_attr[groupname_field]
                group_attr[groupname_field] = groupname.lower()
            except KeyError:
                logger.warning("Group is missing a required attribute '%s'" %
                               groupname_field)
                continue

            kwargs = {
                groupname_field + '__iexact': groupname,
                'defaults': group_attr,
            }

            # Create or update group data in the local database
            try:
                group, created = Group.objects.get_or_create(**kwargs)
            except IntegrityError as e:
                logger.error("Error creating group %s" % e)
            else:
                if created:
                    logger.debug("Created group %s" % groupname)

        logger.info("Groups are synchronized")
dataset/ETHPy150Open jbittel/django-ldap-sync/ldap_sync/management/commands/syncldap.py/Command.sync_ldap_groups/swapped operands of `not in`