Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firebase_admin.db.Reference.listen() don't work when using firebase emulator #844

Open
aiueo-1234 opened this issue Dec 27, 2024 · 0 comments

Comments

@aiueo-1234
Copy link

aiueo-1234 commented Dec 27, 2024

Describe your environment

  • Operating System version: Ubuntu 24.04.1 LTS (WSL)
  • Firebase SDK version: 6.6.0
  • Firebase Product: database
  • Python version: 3.11.2
  • Poetry version: 1.8.4
  • Firebase cli version: 13.27.0
  • Node version: 20.18.0
  • Java openjdk version: 21.0.5

Describe the problem

Steps to reproduce:

When using the firebase emulator, the callback registered with the listen method is not called even if the database value is updated.
However, it will be called correctly when not using the emulator.

Relevant Code:

import os
import time
from datetime import datetime

from firebase_admin import initialize_app
from firebase_admin.credentials import Certificate
from firebase_admin.db import Event, reference

# initialize firebase app
cred = Certificate("path/to/certificate.json")
os.environ["FIREBASE_DATABASE_EMULATOR_HOST"] = "localhost:9000"
app = initialize_app(
    cred,
    options={"databaseURL": "http://localhost:9000/?ns=default-rtdb"},
)


# callback
def callback(event: Event) -> None:
    print(event)


ref = reference(
    "/aaa",
    app=app,
    url=app.options.get("databaseURL"),
)
ref.listen(callback)

for i in range(10):
    ref.child(datetime.now().isoformat(timespec="seconds")).set({"data": i})
    time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants