使用云工作流 firestore 连接器在 Firestore 中插入数据时出现问题,Json 对象来自上一步,这是一个云函数
Issue while inserting Data in Firestore using cloud workflows firestore connector with Json object coming from previous step which is a cloud function
我正在尝试构建一个工作流程,其中在步骤 1 中我是 运行 一个云函数,其中 returns 一个 Json 对象 python 字典的形式,我希望使用 firestore 连接器将其插入到 Firestore 中。但我收到以下错误:
HTTP server responded with error code 400
in step "create_document", routine "main", line: 27
HTTP server responded with error code 400
in step "create_document", routine "main", line: 28
{
"body": {
"error": {
"code": 400,
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"field1\" at 'document.fields[0].value': Cannot find field.",
"field": "document.fields[0].value"
},
{
"description": "Invalid value at 'document.fields[1].value' (type.googleapis.com/google.firestore.v1.Value), 200",
"field": "document.fields[1].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Alt-Svc\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Cache-Control\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Content-Length\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Content-Type\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Date\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
}
我的工作流程是这样的
main:
params: [args]
steps:
- step1:
call: http.get
args:
url: https://XXXXXXXXXXXXX.cloudfunctions.net/step1-workflow
query:
bucket_name: ${args.bucket_name}
blob_name: ${args.blob_name}
result: key_val
- step2:
assign:
- project_id: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
- collection: "a-dummy-collection"
- document: "new7-dummy-document"
- create_document:
call: googleapis.firestore.v1.projects.databases.documents.createDocument
args:
collectionId: ${collection}
parent: ${"projects/" + project_id + "/databases/(default)/documents"}
query:
documentId: ${document}
body:
fields: ${key_val}
result: inserted
if 代替 ${key_val} 我使用简单的 json {"field1": {"stringValue": "str1"},"field2": {"integerValue": 10 }} 它工作正常,数据被插入到 Firestore 中,但是如果我尝试使用变量 ${key_val} 中的对象,它与提到的 json 具有相同的结构,它会出错。
评论中给出的答案:调用云函数的 ${key_val}
结果实际上返回了整个响应 object,而不仅仅是 body。这就是为什么在错误消息中,您会看到诸如 content-type
和其他 headers.
之类的内容
这里的解决方案是说我们希望该响应的 body 具有:${key_val.body}
.
我正在尝试构建一个工作流程,其中在步骤 1 中我是 运行 一个云函数,其中 returns 一个 Json 对象 python 字典的形式,我希望使用 firestore 连接器将其插入到 Firestore 中。但我收到以下错误:
HTTP server responded with error code 400
in step "create_document", routine "main", line: 27
HTTP server responded with error code 400
in step "create_document", routine "main", line: 28
{
"body": {
"error": {
"code": 400,
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"field1\" at 'document.fields[0].value': Cannot find field.",
"field": "document.fields[0].value"
},
{
"description": "Invalid value at 'document.fields[1].value' (type.googleapis.com/google.firestore.v1.Value), 200",
"field": "document.fields[1].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Alt-Svc\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Cache-Control\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Content-Length\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Content-Type\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Date\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
}
我的工作流程是这样的
main:
params: [args]
steps:
- step1:
call: http.get
args:
url: https://XXXXXXXXXXXXX.cloudfunctions.net/step1-workflow
query:
bucket_name: ${args.bucket_name}
blob_name: ${args.blob_name}
result: key_val
- step2:
assign:
- project_id: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
- collection: "a-dummy-collection"
- document: "new7-dummy-document"
- create_document:
call: googleapis.firestore.v1.projects.databases.documents.createDocument
args:
collectionId: ${collection}
parent: ${"projects/" + project_id + "/databases/(default)/documents"}
query:
documentId: ${document}
body:
fields: ${key_val}
result: inserted
if 代替 ${key_val} 我使用简单的 json {"field1": {"stringValue": "str1"},"field2": {"integerValue": 10 }} 它工作正常,数据被插入到 Firestore 中,但是如果我尝试使用变量 ${key_val} 中的对象,它与提到的 json 具有相同的结构,它会出错。
评论中给出的答案:调用云函数的 ${key_val}
结果实际上返回了整个响应 object,而不仅仅是 body。这就是为什么在错误消息中,您会看到诸如 content-type
和其他 headers.
这里的解决方案是说我们希望该响应的 body 具有:${key_val.body}
.