Firestore 触发器 Python 云函数(第 2 代)- 采用 1 个位置参数,但已给出 2 个

问题描述 投票:0回答:1

我已经按照示例部署了 firestore 触发函数 on_document_createdhttps://firebase.google.com/docs/reference/functions/2nd-gen/python/firebase_functions.firestore_fn#functions

@on_document_created(document="test/{testId}")
def example(event: Event[DocumentSnapshot]):
  print("Hello World")
  pass

为了部署它,我使用了以下命令:

gcloud functions deploy example --gen2 --trigger-event-filters=type=google.cloud.firestore.document.v1.created --trigger-event-filters=database='(default)' --trigger-event-filters-path-pattern=document='' --project test-project --runtime python311 --memory 512 --region europe-west3 --env-vars-file prod.yml

每当在 firestore 上创建文档时,都会正确调用该函数,但我在日志中收到以下错误:

TypeError: example() takes 1 positional argument but 2 were given

我不知道我做错了什么。 你能帮我吗?

谢谢你

python firebase google-cloud-firestore google-cloud-functions
1个回答
0
投票

由于您遵循 Firebase 文档,因此您应该使用 Firebase CLI 部署到 Cloud Functions。该 CLI(与

gcloud
不同)添加了 Google Cloud 所需的附加信息。

有关此内容的更多信息,请参阅有关 使用 firebase deploy

部署云函数的 
Firebase 文档。

© www.soinside.com 2019 - 2024. All rights reserved.