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

Firebase Cloud Function未触发问题排查求助

问题分析与修改方案
  • 核心错误:装饰器冲突
    你的函数同时使用了@https_fn.on_call和@on_document_updated两个装饰器,这是不允许的——一个函数只能绑定一种触发器类型。HTTP Callable函数需要客户端主动调用,而Firestore更新触发器是被动监听文档变化,两者不能混用。

  • 修改步骤:

    1. 移除@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"
        })
      
    2. 重新部署云函数:
      使用Firebase CLI执行部署命令:
      firebase deploy --only functions:paid_for_request
      
    3. 额外检查点:
      • 确认云函数的服务账号拥有datastore.user权限(默认已配置,若手动修改过权限需验证)
      • 查看Firebase控制台的函数日志,排查是否有报错信息(比如权限不足、代码语法错误)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 17:04:54