Checklist
Mandatory Debugging Information
- Celery version: 5.6.1
- Flower version: 2.0.1
- Python version: 3.12
- OS: Linux (Docker container)
- Broker: Redis
- Result backend: Redis
Description
When starting Flower with a Django/Celery application, an AttributeError is raised in celery/fixups/django.py at line 220.
The error occurs because self.worker.pool_cls is a string ('prefork') instead of a class object, so accessing .__module__ fails.
Error Traceback
File "/usr/local/lib/python3.12/site-packages/celery/fixups/django.py", line 220, in _close_database
is_prefork = "prefork" in self.worker.pool_cls.__module__
│ │ └ 'prefork'
│ └ <Worker: celery@75efc8aa2596 (INIT)>
└ <celery.fixups.django.DjangoWorkerFixup object at 0x7f77b5998f20>
AttributeError: 'str' object has no attribute '__module__'. Did you mean: '__mod__'?
Full Stack Trace
File "/usr/local/lib/python3.12/site-packages/celery/fixups/django.py", line 116, in on_worker_init
self.worker_fixup.install()
File "/usr/local/lib/python3.12/site-packages/celery/fixups/django.py", line 161, in install
self.close_database()
File "/usr/local/lib/python3.12/site-packages/celery/fixups/django.py", line 207, in close_database
return self._close_database()
File "/usr/local/lib/python3.12/site-packages/celery/fixups/django.py", line 220, in _close_database
is_prefork = "prefork" in self.worker.pool_cls.__module__
AttributeError: 'str' object has no attribute '__module__'
Steps to Reproduce
- Set up a Django project with Celery 5.6.1
- Install Flower 2.0.1
- Run Flower:
celery -A your_app flower --port=5555
- Observe the AttributeError in logs
Expected Behavior
Flower should start without errors.
Actual Behavior
An AttributeError is raised because pool_cls is a string instead of a class object when the Django fixup code tries to check if the pool is prefork.
Root Cause Analysis
In celery/fixups/django.py line 220:
is_prefork = "prefork" in self.worker.pool_cls.__module__
The code assumes pool_cls is a class with a __module__ attribute, but at this point in the initialization, pool_cls is still a string (e.g., 'prefork').
Suggested Fix
Check if pool_cls is a string before accessing .__module__:
pool_cls = self.worker.pool_cls
if isinstance(pool_cls, str):
is_prefork = "prefork" in pool_cls
else:
is_prefork = "prefork" in pool_cls.__module__
Impact
- Severity: Low (Flower still works despite the error)
- Workaround: None needed - the error is logged but doesn't prevent Flower from functioning
Checklist
mainbranch of Celery.Mandatory Debugging Information
Description
When starting Flower with a Django/Celery application, an
AttributeErroris raised incelery/fixups/django.pyat line 220.The error occurs because
self.worker.pool_clsis a string ('prefork') instead of a class object, so accessing.__module__fails.Error Traceback
Full Stack Trace
Steps to Reproduce
celery -A your_app flower --port=5555Expected Behavior
Flower should start without errors.
Actual Behavior
An
AttributeErroris raised becausepool_clsis a string instead of a class object when the Django fixup code tries to check if the pool is prefork.Root Cause Analysis
In
celery/fixups/django.pyline 220:The code assumes
pool_clsis a class with a__module__attribute, but at this point in the initialization,pool_clsis still a string (e.g.,'prefork').Suggested Fix
Check if
pool_clsis a string before accessing.__module__:Impact