def lookup_rows(self, key, values, fields=[]):
        """
            Custom rows lookup function

            @param key: the key field
            @param values: the values to look up
            @param fields: unused (retained for API compatibility)
        """

        db = current.db
        s3db = current.s3db

        instance_fields = {
            "event_asset": ["incident_id", "asset_id"],
            "event_site": ["incident_id", "site_id"],
            "event_human_resource": ["incident_id", "human_resource_id"],
        }

        # Get all super-entity rows
        etable = s3db.budget_cost_item
        rows = db(key.belongs(values)).select(key,
                                              etable.instance_type)
        self.queries += 1

        # Sort the super-entity rows by instance type
        keyname = key.name
        types = {}
        for row in rows:
            instance_type = row.instance_type
            cost_item_id = row[keyname]
            if instance_type not in types:
                types[instance_type] = {cost_item_id: row}
            else:
                types[instance_type][cost_item_id] = row

        # Get all instance records (per instance type)
        results = []
        append = results.append
        for instance_type in types:

            # Determine instance table
            table = s3db.table(instance_type)
            if not table:
                continue

            # Determine instance fields
            fields = []
            bulk_repr = {}
            if instance_fields in instance_type:
                for fname in instance_fields[instance_type]:
                    field = table[fname]
                    # Supports bulk representation?
                    if fname in self.represent:
                        represent = self.represent[fname]
                    else:
                        represent = field.represent
                    if represent and hasattr(represent, "bulk"):
                        bulk_repr[fname] = {"method": represent, "values": []}
                    fields.append(field)
            else:
                continue
            fields.insert(0, table[keyname])

            # Extract instance rows
            query = (table[keyname].belongs(types[instance_type].keys()))
            rows = db(query).select(*fields)
            self.queries += 1

            # Construct result rows
            sdata = types[instance_type]
            for row in rows:
                for fname, frepr in bulk_repr.items():
                    frepr["values"].append(row[fname])
                # Construct a new Row which contains both, the super-entity
                # record and the instance record:
                append(Row(budget_cost_item = sdata[row[keyname]],
                           **{instance_type: row}))

            # Bulk representation of instance fields:
            # The results are stored in S3Represent instance, and there they
            # will be re-used for single-value representation in represent_row
            for fname, frepr in bulk_repr.items():
                frepr["method"].bulk(frepr["values"])

        return results

    # -------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/modules/s3db/budget.py/budget_CostItemRepresent.lookup_rows/swapped operands of `in`