Pyrebase4 icon indicating copy to clipboard operation
Pyrebase4 copied to clipboard

Cannot store database reference in variable

Open FinnMal opened this issue 3 years ago • 0 comments

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

FinnMal avatar Nov 22 '21 19:11 FinnMal