django-celery-beat icon indicating copy to clipboard operation
django-celery-beat copied to clipboard

perf: respect django database routing

Open systemime opened this issue 4 years ago • 5 comments

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.

systemime avatar Nov 02 '21 05:11 systemime

@D3X @lvelvee can you try this pr to verify it won't introduce any regression?

auvipy avatar Dec 15 '21 11:12 auvipy

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

systemime avatar Jan 20 '22 04:01 systemime

using django unit test is a good start, I will take some time to properly review & test it before merge

auvipy avatar Jan 20 '22 05:01 auvipy

@954-Ivory please review this whenever you have chance

auvipy avatar Oct 13 '22 12:10 auvipy