Repository: Mailu/Mailu

Issue:
admin container on master branch fails with mysql
Thank you for opening an issue with Mailu. Please understand that issues are meant for bugs and enhancement-requests.
For **user-support questions**, reach out to us  on [matrix](https://matrix.to/#/#mailu:tedomum.net).

To be able to help you best, we need some more information.

## Before you open your issue
- [*] Check if no issue or pull-request for this already exists.
- [*] Check [documentation](https://mailu.io/master/) and [FAQ](https://mailu.io/master/faq.html). (Tip, use the search function on the documentation page)
- [*] You understand `Mailu` is made by volunteers in their **free time** — be conscise, civil and accept that delays can occur.
- [*] The title of the issue should be short and simple. It should contain specific terms related to the actual issue. Be specific while writing the title.

## Environment & Versions
### Environment
 - [*] docker-compose
 - [ ] kubernetes
 - [ ] docker swarm

### Versions
To find your version, get the image name of a mailu container and read  the version from the tag (example for version 1.7).
```
image: ${DOCKER_ORG:-mailu}/${DOCKER_PREFIX:-}admin:${MAILU_VERSION:-master}
```

## Description
The last 2-3 admin builds of the master branch fail on mysql with this error:
ModuleNotFoundError: No module named 'MySQLdb'
This is not a production environment, just wanted to report.
My mysql server is as follows, but with the admin:1.9 image the setup works properly, so it isn't a mysql issue.
mysql  Ver 15.1 Distrib 10.8.4-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper


## Replication Steps
Steps for replicating your issue

## Expected behaviour

## Logs

````markdown
```
admin_1      | Traceback (most recent call last):
admin_1      |   File "/usr/lib/python3.9/site-packages/sqlalchemy/util/_collections.py", line 1008, in __call__
admin_1      |     return self.registry[key]
admin_1      | KeyError: <greenlet.greenlet object at 0x7f231b79da90 (otid=0x7f231b623340) current active started main>
admin_1      | During handling of the above exception, another exception occurred:
admin_1      | Traceback (most recent call last):
admin_1      |   File "/usr/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
admin_1      |     response = self.full_dispatch_request()
admin_1      |   File "/usr/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
admin_1      |     rv = self.handle_user_exception(e)
admin_1      |   File "/usr/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
admin_1      |     rv = self.dispatch_request()
admin_1      |   File "/usr/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
admin_1      |     return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
admin_1      |   File "/app/mailu/sso/views/base.py", line 49, in login
admin_1      |     return flask.render_template('login.html', form=form, fields=fields)
admin_1      |   File "/usr/lib/python3.9/site-packages/flask/templating.py", line 146, in render_template
admin_1      |     ctx.app.update_template_context(context)
admin_1      |   File "/usr/lib/python3.9/site-packages/flask/app.py", line 756, in update_template_context
admin_1      |     context.update(func())
admin_1      |   File "/app/mailu/__init__.py", line 54, in inject_defaults
admin_1      |     signup_domains = models.Domain.query.filter_by(signup_enabled=True).all()
admin_1      |   File "/usr/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 552, in __get__
admin_1      |     return type.query_class(mapper, session=self.sa.session())
admin_1      |   File "/usr/lib/python3.9/site-packages/sqlalchemy/orm/scoping.py", line 47, in __call__
admin_1      |     sess = self.registry()
admin_1      |   File "/usr/lib/python3.9/site-packages/sqlalchemy/util/_collections.py", line 1010, in __call__
admin_1      |     return self.registry.setdefault(key, self.createfunc())
admin_1      |   File "/usr/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 4172, in __call__
admin_1      |     return self.class_(**local_kw)
admin_1      |   File "/usr/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 176, in __init__
admin_1      |     bind = options.pop('bind', None) or db.engine
admin_1      |   File "/usr/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 998, in engine
admin_1      |     return self.get_engine()
admin_1      |   File "/usr/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 1017, in get_engine
admin_1      |     return connector.get_engine()
admin_1      |   File "/usr/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 594, in get_engine
admin_1      |     self._engine = rv = self._sa.create_engine(sa_url, options)
admin_1      |   File "/usr/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 1027, in create_engine
admin_1      |     return sqlalchemy.create_engine(sa_url, **engine_opts)
admin_1      |   File "<string>", line 2, in create_engine
admin_1      |   File "/usr/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py", line 298, in warned
admin_1      |     return fn(*args, **kwargs)
admin_1      |   File "/usr/lib/python3.9/site-packages/sqlalchemy/engine/create.py", line 560, in create_engine
admin_1      |     dbapi = dialect_cls.dbapi(**dbapi_args)
admin_1      |   File "/usr/lib/python3.9/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 167, in dbapi
admin_1      |     return __import__("MySQLdb")
admin_1      | ModuleNotFoundError: No module named 'MySQLdb'

```
````



Discussion:
when i use v1.9.34, i meet the same error.
i downgrade to v1.9.26 no error.
ACK. https://github.com/Mailu/Mailu/pull/2422/files is what broke it.

Resolving patch:
diff --git a/core/admin/mailu/configuration.py b/core/admin/mailu/configuration.py
--- a/core/admin/mailu/configuration.py
+++ b/core/admin/mailu/configuration.py
@@ -98,7 +98,7 @@ class ConfigManager:
     DB_TEMPLATES = {
         'sqlite': 'sqlite:////{SQLITE_DATABASE_FILE}',
         'postgresql': 'postgresql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}',
-        'mysql': 'mysql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}'
+        'mysql': 'mysql+mysqlconnector://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}'
     }
 
     def __init__(self):


Test patch: