Firebase Cloud Function未触发问题排查求助
问题分析与修改方案
核心错误:装饰器冲突
你的函数同时使用了@https_fn.on_call和@on_document_updated两个装饰器,这是不允许的——一个函数只能绑定一种触发器类型。HTTP Callable函数需要客户端主动调用,而Firestore更新触发器是被动监听文档变化,两者不能混用。修改步骤:
- 移除
@https_fn.on_call(max_instances=10)装饰器,保留Firestore更新触发器装饰器:from firebase_admin import firestore, initialize_app import google.cloud.firestore from firebase_functions import firestore_fn from firebase_functions.firestore_fn import ( on_document_updated, Event, Change, DocumentSnapshot, ) initialize_app() @firestore_fn.on_document_updated(document="user_requests/{requestID}") def paid_for_request(event: Event[Change[DocumentSnapshot]]) -> None: firestore_client: google.cloud.firestore.Client = firestore.client() firestore_client.document("notifications/test").set({ "body": "Hello" }) - 重新部署云函数:
使用Firebase CLI执行部署命令:firebase deploy --only functions:paid_for_request - 额外检查点:
- 确认云函数的服务账号拥有
datastore.user权限(默认已配置,若手动修改过权限需验证) - 查看Firebase控制台的函数日志,排查是否有报错信息(比如权限不足、代码语法错误)
- 确认云函数的服务账号拥有
- 移除
内容的提问来源于stack exchange,提问作者ron
相关产品推荐
相关产品推荐

