Ejemplo n.º 1
0
def _by_uuids(field, ids, validate, include):
    query = "IN (" if include else "NOT IN ("
    # trick to workaround postgresql, it does not allow returning ():
    empty_query = "IS NULL" if include else "IS NOT NULL"
    if ids:
        try:
            validate_uuids(ids)
            ids_list = [_format_uuid(identifier) for identifier in ids]
            return UnaryExpression(
                field, modifier=operators.custom_op(query + ",".join(ids_list) + ")")
            )
        except UUIDValidationError:
            # the value is not a valid hex code for a UUID, so fall through to the
            # empty case and don't return any results
            pass
    return UnaryExpression(field, modifier=operators.custom_op(empty_query))
Ejemplo n.º 2
0
def _by_uuids(field, ids, validate, include, vendor=None):
    query = "IN (" if include else "NOT IN ("
    # trick to workaround postgresql, it does not allow returning ():
    empty_query = "IS NULL" if include else "IS NOT NULL"
    if ids:
        if len(ids) > 10000:
            logger.warn(
                """
                More than 10000 UUIDs passed to filter by uuids method,
                these should be batched into separate querysets to avoid SQL Query too large errors in SQLite
            """
            )
        try:
            validate_uuids(ids)
            ids_list = [_format_uuid(identifier, vendor=vendor) for identifier in ids]
            return UnaryExpression(
                field, modifier=operators.custom_op(query + ",".join(ids_list) + ")")
            )
        except UUIDValidationError:
            # the value is not a valid hex code for a UUID, so fall through to the
            # empty case and don't return any results
            pass
    return UnaryExpression(field, modifier=operators.custom_op(empty_query))