Datastore emulator causes firebase admin to hang

未关闭
#790 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
python

调研方向

首先运行报告中的 datastore emulator 命令和提供的 Python 脚本,重点关注从 datastore_client.context() 到 auth.get_user_by_email() 的转换。比较移除三行 datastore context 后的行为。当 datastore emulator 运行时 Firebase Auth 查找正常返回,并且进程仍可中断,即表示完成。

由索引模型根据 Issue 内容生成。

描述

api: auth
[REQUIRED] Step 2: Describe your environment
  • Operating System version: Mac 14.5
  • Firebase Product: firebase-admin==6.2.0 and firebase-admin==6.5.0
  • Python version: 3.11.4
  • Pip version: 24.0
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:

This problem started around June 1. Before, I have been doing this for several years without any issues.

The problem is that auth.get_user_by_email() freezes and it is caused by some interaction with running the cloud datastore emulator locally. This happens with either the older emulator (gcloud beta emulators datastore start) or the newer one (gcloud emulators firestore start ). I have tried downgrading gcloud and two versions of firebase-admin listed above.

Run the script below. At auth.get_user_by_email(), the script hangs indefinitely with no output. You can't even ctrl-c to stop the script. You need to kill -9 in a separate terminal window.

If you comment out the three lines starting with with datastore_client.context():, then auth.get_user_by_email() works.

Since the code just freezes, I am at a loss as to how to debug.

Relevant Code:
import os
from google.cloud import ndb
import firebase_admin
from firebase_admin import auth, initialize_app

print('starting')

class User(ndb.Model):
    email = ndb.StringProperty(required=True)

os.environ['DATASTORE_DATASET'] = 'my-project'
os.environ['DATASTORE_EMULATOR_HOST'] = 'localhost:8081'
os.environ['DATASTORE_EMULATOR_HOST_PATH'] = 'localhost:8081/datastore'
os.environ['DATASTORE_HOST'] = 'http://localhost:8081'
os.environ['DATASTORE_PROJECT_ID']= 'my-project'

datastore_client = ndb.Client('my-project')

if not firebase_admin._apps:
    initialize_app()

email = 'me@example.com'

with datastore_client.context():
    user = User.get_by_id(email)
    print(user)

# This hangs and you can't even ctrl-c to stop.
# Works if datastore client stuff is commented out.
fb_user = auth.get_user_by_email(email)
print(fb_user)
主要语言
Python
星标
1.2k
派生
359
平均合并
5 天 6 分钟
30 天内合并 PR
2

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

firebase/firebase-admin-python 的其他 Issue

查看 firebase/firebase-admin-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。