def METHOD_NAME(pk):
    try:
        query = UIQuery.objects.get(id=pk)
    except UIQuery.DoesNotExist:
        raise generic_api_exceptions.NotFoundAPIException(
            NotFound,
            error_code=ErrorCodes.QueryNotFound.value,
            message="Query doesn't exist"
        )
    return query