-
Notifications
You must be signed in to change notification settings - Fork 456
perf: respect django database routing #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
perf: respect django database routing #451
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also add relevant test ?
ab8f2d9
to
e718a8b
Compare
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. |
using django unit test is a good start, I will take some time to properly review & test it before merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests are failing. also please rebase
I tried to rebase and fix the conflicts to see where it stands right now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request improves Django database routing support for django-celery-beat by ensuring the proper database connection is used when multiple databases are configured.
- Adds a Router class and overrides DATABASE_ROUTERS in tests to simulate different routing scenarios.
- Adapts transaction handling in schedulers to commit and run within the correct database using a new target_db property.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
t/unit/test_schedulers.py | Updates tests to include DATABASE_ROUTERS and ROOT_URLCONF overrides for simulating routing. |
django_celery_beat/schedulers.py | Adds a target_db property and updates transaction handling to respect the correct database. |
Co-authored-by: Copilot <[email protected]>
=========================== short test summary info ============================ |
Summary:
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.