Skip to content
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

Add support for django with multiple databases #53

Merged

Conversation

NyanKiyoshi
Copy link
Contributor

The changes proposed allow to switch schema for all connections rather than the only default database.

The changes assume that all connections are always on the same schema as the first connection ('default'), meaning the tasks are not switching schema during their execution. Thus that we don't need to check all connections whether they are on a different schema or not.

The lines where the assumption is made:

Solves #52

This allows to switch schema for all connections rather than the only default database.

The changes assume that all connections are always on the same schema as the first connection (`'default'`), meaning the tasks are not switching schema during their execution. Thus that we don't need to check all connections whether they are on a different schema or not.

The lines where the assumption is made:
- app.py:33
- app.py:39
- app.py:42
- app.py:46
- app.py:65
Django 4.0 dropped `django.conf.urls.url()` for `django.urls.re_path()`
@maciej-gol
Copy link
Owner

maciej-gol commented Jan 31, 2022

Hey, @NyanKiyoshi! Thanks for this MR! The changes look very good. Could you please add tests coverage, too?

Also, this is not a backwards-compatible change. Could you please add a settings to control this behavior? We could make it a list of db names defaulting to ["default"].

@NyanKiyoshi
Copy link
Contributor Author

Hey, @NyanKiyoshi! Thanks for this MR! The changes look very good. Could you please add tests coverage, too?

Also, this is not a backwards-compatible change. Could you please add a settings to control this behavior? We could make it a list of db names defaulting to ["default"].

Hi @maciej-gol,

Great suggestion! I pushed 127b266 with the requested changes. If it looks good, then I will update the readme file as well to reflect the changes.

Do note that in the test case test_use_multiple_databases I was unable to make test cases where one would change the setting (settings.py via the settings fixture or celery.conf). This is due to the fact the Celery worker is running outside the tests, making the tests unable to change the configuration on the fly.

But I do believe the test case is enough, I added test_get_tenant_databases_custom_settings which ensures the configuration is read properly to counter that limitation.

Second, I did not add CELERY_TASK_TENANT_DATABASES to the test app's settings.py as I believe it is preferable to test against default config and then have specific test cases checking for the custom config; making it easier to override than having to attempt to override the Celery worker's config.

Let me know your feedbacks

@maciej-gol maciej-gol merged commit dcdb96b into maciej-gol:master Feb 4, 2022
@maciej-gol
Copy link
Owner

Thanks for this improvement! Everything looks sound! Also, thanks for explaining your testing approach - very reasonable one, I like it :D

@NyanKiyoshi NyanKiyoshi deleted the feature/support-multiple-databases branch February 7, 2022 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants