Open rickbau5 opened 1 year ago
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Yo we need this implemented. Having massive issues in production, most of notifications are not working due to this shitty handling of initialization
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: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 exceptionsource
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
variablesource
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:
This could then be used:
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.