django-celery-beat
django-celery-beat copied to clipboard
perf: respect django database routing
Summary:
- Celery Version: 5.1.2
- Celery-Beat Version: 2.2.1
The problem you want to solve
If the django project is configured with multiple databases, the default behavior in the django-celery-beat will cause django to get the default database connection, but at this time it is an empty dictionary, and then a database configuration exception will be thrown. This pr will check the DATABASE_ROUTERS to determine whether django db router is needed.
@D3X @lvelvee can you try this pr to verify it won't introduce any regression?
Sorry, I'm trying to add unit tests for here but don't have any good ideas. I referenced Django's unit tests and used the override_settings decorator to simulate the multidb case. By default, the Router's db_for_write method returning None will cause Django to use the default database configuration, regardless of whether the user is using multidb or not.
@auvipy
using django unit test is a good start, I will take some time to properly review & test it before merge
@954-Ivory please review this whenever you have chance