[FR] Improve Ability to detect if App has been Initialized
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia leggendo firebase_admin/init.py, in particolare initialize_app() e get_app() nelle vicinanze delle righe collegate. Confronta la funzione is_initialized proposta e gli approcci basati su errori specifici, quindi determina quale comportamento pubblico desiderano i maintainer. Il lavoro è completato quando gli utenti possono rilevare in modo affidabile se l’app richiesta è inizializzata senza ispezionare la variabile privata _apps o analizzare un ValueError generico.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Is your feature request related to a problem? Please describe.
Currently there is not a way offered by the library to check if firebase_admin.initialize_app(...)(source) has been called and an app has been initialized besides catching an exception. This can result in library users seeing the following exception:
ValueError: The default Firebase app already exists. This means you called initialize_app() more than once without providing an app name as the second argument. In most cases you only need to call initialize_app() once. But if you do want to initialize multiple apps, pass a second argument to initialize_app() to give each app a unique name.
source
From the discussion in this Stackoverflow post, there are two main approaches library users have implemented:
1. use a try/except block on ValueError to get the app and initialize it if there is an exception
try:
app = firebase_admin.get_app()
except ValueError as e:
cred = credentials.Certificate(CREDENTIALS_FIREBASE_PATH)
firebase_admin.initialize_app(cred)
Pros: simple
Cons: ValueError is a general error so theoretically the use does not know for sure the error is regarding initialization, so further inspection is needed to verify that the error is related to app initialization, e.g. a string check on "already exists".
2. check the "private" _apps variable
if not firebase_admin._apps:
cred = credentials.Certificate('path/to/serviceAccountKey.json')
default_app = firebase_admin.initialize_app(cred)
Pros: not relying on try/except flow
Cons: accessing a "private" variable, as the library owners now if you change this variable it will cause breaking changes for many library users.
Describe the solution you'd like
Option 1: Implement a function like is_initialized(name=_DEFAULT_APP_NAME)
This could check _apps for the given name and return true / false for whether it is initialized.
Option 2: Raise a specific error
Implement a new error that extends ValueError for backwards compatibility and raise the error with this new type.
For example:
class AppInitializedError(ValueError):
def __init__(self, message):
super().__init__(message)
This could then be used:
try:
app = firebase_admin.get_app()
except AppInitializedError:
cred = credentials.Certificate(CREDENTIALS_FIREBASE_PATH)
firebase_admin.initialize_app(cred)
These implementations could be done in conjunction, however option 1 is safest as it only adds new behavior and changes no existing behavior. Furthermore there will still be those against using try / except as the "expected" way to check if the app is initialized as offered in option 2.
Describe alternatives you've considered
The alternatives are described in the stackoverflow post above (link) as well as in this issue.
- Lingua principale
- Python
- Stelle
- 1.2k
- Fork
- 359
- Merge medio
- 5g 6m
- PR unite (30g)
- 2
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di firebase/firebase-admin-python
-
api: remoteconfig
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
firebase/firebase-admin-python#957 · 1 commento ·
-
api: database type: feature request
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
firebase/firebase-admin-python#978 · 1 commento ·
-
[FR] Support VERIFY_AND_CHANGE_EMAIL in generate_email_action_link (parity with firebase-admin-node) Apertaapi: auth
firebase/firebase-admin-python#949 · 2 commenti · 1 reazione · 1 assegnatario ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 43/100
firebase/firebase-admin-python#945 · 1 commento · 1 reazione ·
Tutte le issue di firebase/firebase-admin-python
Issue simili
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
canonical/paas-charm#368 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
tech debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
addition to tracking list Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
StevenBlack/hosts#3256 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
qualcomm/qai-appbuilder#275 ·