nhorvath / Pyrebase4

A simple python wrapper for the Firebase API. ⛺
248 stars 61 forks source link

Cannot store database reference in variable #44

Open FinnMal opened 2 years ago

FinnMal commented 2 years ago

To make the code cleaner, I save the database references in a variable. However, this may lead to my entire database being deleted.

If I do NOT query the value from the database before "set ('test')", everything works as expected. If the value is loaded from the database beforehand, the complete database is deleted after "set". If only the value is queried from the database, nothing is deleted either.

Python version: 3.7.4 Pyrebase4 version: 4.5.0

This code deletes the database:

import pyrebase

firebase_config = {
    "apiKey": "..",
    "authDomain": "...",
    "databaseURL": "...",
    "projectId": "...",
    "storageBucket": "...",
    "messagingSenderId": "...",
    "appId": "...",
    "serviceAccount": '...'
}

firebase = pyrebase.initialize_app(firebase_config)
db = firebase.database()

queue_id = db.child('queue_id').child('4IYNzoZ63Am2XYkxMFXsN7').get().val()
status_ref = db.child('queue').child(queue_id).child('status')

status = status_ref.get().val()

status_ref.set('test')

And this works fine:

queue_id = db.child('queue_id').child('4IYNzoZ63Am2XYkxMFXsN7').get().val()
status_ref = db.child('queue').child(queue_id).child('status')

# status = status_ref.get().val()

status_ref.set('test')

After the "deletion" my database looks like this: database_empty