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

Make Celery Result Backend work when there are multiple database but no default #323

Closed
nofalx opened this issue Jun 21, 2022 · 2 comments
Closed

Comments

@nofalx
Copy link
Contributor

nofalx commented Jun 21, 2022

I detect this issue occurring after i set up multiple database with no default DB in

ImproperlyConfigured 
celery.backend_cleanup
settings.DATABASES is improperly configured. Please supply the ENGINE value. Check..

My Django setting as below

CELERY_QUEUE = "queue_one"
CELERY_RESULT_BACKEND = "django-db"
DATABASES = {
    "default": {},
    "main": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "..",
        "USER": "..",
        "PASSWORD": "..",
        "HOST": "..",
        "PORT": "..",  
    },
    "datalake": {
        "ENGINE": "timescale.db.backends.postgresql",
        "NAME": "..",
        "USER": "..",
        "PASSWORD": "..",
        "HOST": "..",
        "PORT": "..",  
    },
}
DATABASE_ROUTERS = [
    "app.db_routers.TimeScaleRouter",
    "app.db_routers.MainRouter",
]

The issue occurs because we are trying to perform an atomic transaction at

The line transaction.atomic() will always point to the default db if you look at the django source code at:
https://github.com/django/django/blob/2887b9f67cadc5295ef6a0574de2c2c8fdd66905/django/db/transaction.py#L315

I tried to read the documentation and see if we can specify which DATABASES we can manually specify which db but i failed to find it, in case of settings above main or datalake.

Im assuming the database is determined using the DATABASE_ROUTERS, in this case can we somehow inject the db name into the atomic transaction like this:

transaction.atomic(using=self.db)

@auvipy
Copy link
Member

auvipy commented Jun 21, 2022

I think https://github.com/celery/django-celery-beat/pull/451/files is somehow related to what you are thinking

@auvipy
Copy link
Member

auvipy commented Jun 29, 2022

released

@auvipy auvipy closed this as completed Jun 29, 2022
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

No branches or pull requests

2 participants