Pyrebase4
Pyrebase4 copied to clipboard
Cannot store database reference in variable
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: