{"id":22445,"library":"tenant-schemas-celery","title":"tenant-schemas-celery","description":"Celery integration for django-tenant-schemas and django-tenants. Automatically sets the schema on Celery task invocations so that tasks run in the correct tenant context. Current version is 4.0.3, supporting Python >=3.9. Release cadence is irregular, with major versions aligned with Django or Celery breaking changes.","status":"active","version":"4.0.3","language":"python","source_language":"en","source_url":"https://github.com/maciej-gol/tenant-schemas-celery","tags":["django","celery","multi-tenant","schema","postgres"],"install":[{"cmd":"pip install tenant-schemas-celery","lang":"bash","label":"Default install"}],"dependencies":[{"reason":"Required by the underlying tenant library","package":"Django","optional":false},{"reason":"Required for tenant context; or django-tenant-schemas (legacy)","package":"django-tenants","optional":false},{"reason":"Required for task queue integration","package":"Celery","optional":false}],"imports":[{"note":"CeleryApp is in the app submodule, not directly in the package root.","wrong":"from tenant_schemas_celery import CeleryApp","symbol":"CeleryApp","correct":"from tenant_schemas_celery.app import CeleryApp"}],"quickstart":{"code":"import os\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'your_project.settings')\n\nfrom tenant_schemas_celery.app import CeleryApp\n\napp = CeleryApp('your_project')\napp.config_from_object('django.conf:settings', namespace='CELERY')\napp.autodiscover_tasks()","lang":"python","description":"Create a Celery app instance that automatically manages tenant schema context. Replace 'your_project' with your Django project name."},"warnings":[{"fix":"Upgrade to 4.0.0+ and use django-tenants instead of django-tenant-schemas.","message":"Version 4.0.0 dropped support for django-tenant-schemas (legacy) and Python <3.9. If you need the old package, pin to <4.0.0.","severity":"breaking","affected_versions":"<4.0.0"},{"fix":"Use app.Task to inherit tenant schema support in custom tasks, or set app.Task = YourCustomTask in CeleryApp.","message":"Version 3.0.0 introduced a custom task class via CeleryApp overriding the default Task class. If you have custom task base classes, they may not be applied unless you set the Task class explicitly.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Replace with `from tenant_schemas_celery.app import CeleryApp`.","message":"Using `from tenant_schemas_celery import CeleryApp` is deprecated and will be removed. Import from the `app` submodule instead.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Ensure tasks are called from within a tenant context (e.g., inside a view or with `tenant_context()`) or manually set the schema.","message":"If you use `app.send_task()`, the tenant schema is set correctly. However, tasks called via `.delay()` or `.apply_async()` from outside a tenant context (e.g., in a management command) will fail if no active schema is set.","severity":"gotcha","affected_versions":"all"},{"fix":"Set `CELERY_BEAT_SCHEDULER = 'tenant_schemas_celery.schedulers.TenantAwareScheduler'` in Django settings.","message":"When using Celery Beat with django-celery-beat, the scheduler must be configured to use the tenant-schemas-celery scheduler to run tasks in the correct tenant context.","severity":"gotcha","affected_versions":">=2.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use `from tenant_schemas_celery.app import CeleryApp`.","cause":"CeleryApp is in the `app` submodule, not the package root.","error":"ImportError: cannot import name 'CeleryApp' from 'tenant_schemas_celery'"},{"fix":"Upgrade to 3.0.0+ or use `from tenant_schemas_celery.task import TenantTask` explicitly.","cause":"In versions <3.0.0, the Task class was not exposed. Users might have used `app.Task` incorrectly.","error":"AttributeError: 'CeleryApp' object has no attribute 'Task'"},{"fix":"Always call tasks within a tenant context (e.g., using `connection.set_tenant()`) or pass headers manually via `apply_async(headers={'X-Django-Schema': 'your_schema'})`.","cause":"Tasks were sent without a tenant schema header, possibly from outside a tenant context or using send_task without passing headers.","error":"RuntimeError: No schema name set in task headers. Task will run in public schema."},{"fix":"Upgrade to 3.0.0+ to pass `task_cls`, or set the Task class after instantiation: `app.Task = MyCustomTask`.","cause":"In versions <3.0.0, `task_cls` was not a parameter for CeleryApp.","error":"TypeError: CeleryApp() got an unexpected keyword argument 'task_cls'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}