You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python过滤GCP Workflows失败执行时遇“invalid list filter”错误

解决GCP Workflows Python SDK过滤失败执行的问题

问题原因

gcloud命令中的STATE:FAILED是经过封装的简化过滤语法,但Python SDK直接调用GCP原生API,需要使用API定义的原生字段名——这里执行资源的状态字段是小写的state,而非大写的STATE,这是导致"资源中不存在STATE字段"错误的核心原因。

正确过滤语法

使用state="FAILED"作为过滤条件,示例代码如下:

from google.cloud import workflows_v1

def get_failed_workflow_executions():
    # 初始化客户端
    client = workflows_v1.WorkflowsClient()
    # 指定要查询的工作流路径
    parent = "projects/test-project/locations/europe-west4/workflows/test-workflow"
    # 正确的过滤条件:API原生字段state,值为FAILED枚举值
    filter_condition = 'state="FAILED"'
    
    # 构造请求
    request = workflows_v1.ListExecutionsRequest(
        parent=parent,
        filter=filter_condition
    )
    
    # 分页获取结果
    results = client.list_executions(request=request)
    for execution in results:
        print(f"失败执行ID: {execution.name.split('/')[-1]}")
        print(f"执行状态: {execution.state}")
        print(f"结束时间: {execution.end_time}\n")

if __name__ == "__main__":
    get_failed_workflow_executions()

文档查询位置

在GCP官方的Workflows API参考中,查看ListExecutions接口的filter参数说明,里面会明确列出支持的过滤字段(如state)以及对应的枚举值(FAILED、SUCCEEDED、RUNNING等)。

内容的提问来源于stack exchange,提问作者Ricco Balboa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 05:05:30