GCP Batch unable to list tasks with certain filter expressions

Hi, I tried the following filter:

gcloud batch tasks list --job=job_id --location=location --filter=“NOT STATE=SUCCEEDED” and it returned error

ERROR: (gcloud.batch.tasks.list) INVALID_ARGUMENT: ListTasksRequest.Filter field is invalid. invalid filter string negation:{restriction:{comparator:EQUALS lhs:{value:“STATE”} rhs:{value:“SUCCEEDED”}}}.

and if I try gcloud batch tasks list --job=job_id --location=location --filter=“STATE=PENDING OR STATE=FAILED” it also returned error

ERROR: (gcloud.batch.tasks.list) INVALID_ARGUMENT: ListTasksRequest.Filter field is invalid. invalid filter string disjunction:{expressions:{restriction:{comparator:EQUALS lhs:{value:“STATE”} rhs:{value:“PENDING”}}} expressions:{restriction:{comparator:EQUALS lhs:{value:“STATE”} rhs:{value:“FAILED”}}}}.

Could the team take a look? Thanks!

Hi there,

The Batch team will be pushing a fix out for this particular issue. Meanwhile, to achieve the same request, you could consider using commands like gcloud batch tasks list --job=job_id --location=location --filter=“STATE=FAILED” plus gcloud batch tasks list --job=job_id --location=location --filter=“STATE=PENDING”

Thanks!

Hi, thanks for the reply. Another bug is that if I do gcloud batch tasks list --job=job_id --location=location --filter=“STATE=STATE_UNSPECIFIED” or “STATE=UNEXECUTED”, it will say that it is invalid state even though these are provided here https://cloud.google.com/batch/docs/reference/rest/v1/State

Another bug is on the python api, if i follow the example here https://cloud.google.com/batch/docs/samples/batch-list-tasks

with a minor change to iterate over the tasks and print:

from __future__ import annotations

from collections.abc import Iterable

from google.cloud import batch_v1

def list_tasks(
    project_id: str, region: str, job_name: str, group_name: str
) -> Iterable[batch_v1.Task]:
    """
    Get a list of all jobs defined in given region.

    Args:
        project_id: project ID or project number of the Cloud project you want to use.
        region: name of the region hosting the jobs.
        job_name: name of the job which tasks you want to list.
        group_name: name of the group of tasks. Usually it's `group0`.

    Returns:
        An iterable collection of Task objects.
    """
    client = batch_v1.BatchServiceClient()

    tasks= client.list_tasks(
        parent=f"projects/{project_id}/locations/{region}/jobs/{job_name}/taskGroups/{group_name}"
    )
    for task in tasks:
        print(task)

, it will give error:

google.api_core.exceptions.InvalidArgument: 400 pagesize field is invalid. mismatching token page size error: request page size (0) != token page size (500)

Hello there,

Please try to update to the latest gcloud such as using command gcloud components update and using the gcloud alpha batch tasks list command, hopefully, it would address this issue and your original issue.

Hello there,

I tried the exact Python program as your post and it’s working fine for me, can you please double check your environment like run some other APIs and make sure they are working as intended?