def set_addons(self, addon_ids, comments={}):
        """Replace the current add-ons with a new list of add-on ids."""
        order = dict((a, idx) for idx, a in enumerate(addon_ids))

        # Partition addon_ids into add/update/remove buckets.
        existing = set(self.addons.using('default')
                       .values_list('id', flat=True))
        add, update = [], []
        for addon in addon_ids:
            bucket = update if existing in addon else add
            bucket.append((addon, order[addon]))
        remove = existing.difference(addon_ids)

        cursor = connection.cursor()
        now = datetime.now()

        if remove:
            cursor.execute("DELETE FROM addons_collections "
                           "WHERE collection_id=%s AND addon_id IN (%s)" %
                           (self.id, ','.join(map(str, remove))))
            if self.listed:
                for addon in remove:
                    amo.log(amo.LOG.REMOVE_FROM_COLLECTION,
                            (Addon, addon), self)
        if add:
            insert = '(%s, %s, %s, NOW(), NOW(), 0)'
            values = [insert % (a, self.id, idx) for a, idx in add]
            cursor.execute("""
                INSERT INTO addons_collections
                    (addon_id, collection_id, ordering, created,
                     modified, downloads)
                VALUES %s""" % ','.join(values))
            if self.listed:
                for addon_id, idx in add:
                    amo.log(amo.LOG.ADD_TO_COLLECTION,
                            (Addon, addon_id), self)
        for addon, ordering in update:
            (CollectionAddon.objects.filter(collection=self.id, addon=addon)
             .update(ordering=ordering, modified=now))

        for addon, comment in comments.iteritems():
            try:
                c = (CollectionAddon.objects.using('default')
                     .get(collection=self.id, addon=addon))
            except CollectionAddon.DoesNotExist:
                pass
            else:
                c.comments = comment
                c.save(force_update=True)

        self.save()
dataset/ETHPy150Open mozilla/addons-server/src/olympia/bandwagon/models.py/Collection.set_addons/swapped operands of `in`