[FR] Improve Ability to detect if App has been Initialized
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Comienza leyendo firebase_admin/init.py, especialmente initialize_app() y get_app() cerca de las líneas enlazadas. Compara la función is_initialized propuesta y los enfoques de errores específicos, y determina después qué comportamiento público quieren los maintainers. La tarea estará terminada cuando los usuarios puedan detectar de forma fiable si la app solicitada está inicializada sin inspeccionar la variable privada _apps ni analizar un ValueError general.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 1.2k
- Forks
- 359
- Merge medio
- 5 d 6 min
- PR fusionados (30 d)
- 2
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de firebase/firebase-admin-python
-
api: remoteconfig
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
firebase/firebase-admin-python#957 · 1 comentario ·
-
api: database type: feature request
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
firebase/firebase-admin-python#978 · 1 comentario ·
-
[FR] Support VERIFY_AND_CHANGE_EMAIL in generate_email_action_link (parity with firebase-admin-node) Abiertoapi: auth
firebase/firebase-admin-python#949 · 2 comentarios · 1 reacción · 1 asignado ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 43/100
firebase/firebase-admin-python#945 · 1 comentario · 1 reacción ·
Todos los issues de firebase/firebase-admin-python
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
learningequality/ricecooker#747 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
run-llama/llama_index#23199 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
KhronosGroup/glTF-Blender-IO#2769 ·