alerta/alerta

bson python module not listed in requirements.txt

mtoivo opened this issue · 0 comments

Issue Summary
Alerta will not start, because it does not find python module named bson

Environment

  • OS: Linux

  • API version: 8.7.0

  • Deployment: self-hosted

  • For self-hosted, WSGI environment: nginx/uwsg

  • Database: MongoDB

  • Server config:
    Auth enabled? Yes
    Auth provider? OpenID
    Customer views? No

  • web UI version: 8.7.0

  • CLI version: 8.5.1

To Reproduce
Steps to reproduce the behavior:

  1. Install Alerta and required python modules
  2. Try to start Alerta
  3. Alerta does not start
  4. Logs (uwsgi-logs or console output) tells what modules are missing:
  File "wsgi.py", line 1, in <module>
    from alerta import create_app
  File "[...]/lib/python3.7/site-packages/alerta/__init__.py", line 28, in <module>
    from .app import create_app  # noqa isort:skip
  File "[...]/lib/python3.7/site-packages/alerta/app.py", line 14, in <module>
    from alerta.utils.audit import AuditTrail
  File "[...]/lib/python3.7/site-packages/alerta/utils/audit.py", line 10, in <module>
    from alerta.utils.format import CustomJSONEncoder
  File "[...]/lib/python3.7/site-packages/alerta/utils/format.py", line 5, in <module>
    from bson import ObjectId
ModuleNotFoundError: No module named 'bson'

Expected behavior
Alerta is expected to start when required python modules are installed

Additional context
Problem is solved by installing module named 'bson', but since it's a module alerta will not start without (at least 8.7.0), I guess it should be mentioned in requirements.txt or marked as dependency for alerta.
EDIT(2): Now that I actually looked into the code of format.py in master branch:

        # only required if using MongoDB backend
        try:
            from bson import ObjectId
            if isinstance(o, ObjectId):
                return str(o)
        except ModuleNotFoundError:
            pass

So if I get this right, it is trying to import the module and will just ignore the ModuleNotFoundError (which was not done in 8.7 release). Even though it states that it is only required for MongoDB, I understand that it's absence in might cause some trouble in that case. Maybe there should be conditional to only run this block of code if the backend is Mongo. And perhaps catching the error when using MongoDB should indeed prevent running Alerta and result a simple error message, like "bson module not found, please install it if using MongoDB as backend" or something.