9308831bb8
- Fixed API endpoints to group consumption by (product, equipment) instead of just product - This ensures API returns 350 kg for SILO C only, not 352 kg (summing all SILOs) - Affected endpoints: /api/scada/mo-detail and /api/scada/mo-list-detailed - Files: grt_scada/controllers/main.py, mo_detailed_controller.py - Also fixed OrderedDict mutation race condition in cron thread (odoo server fix applied)
1.9 KiB
1.9 KiB
Fix: RuntimeError - OrderedDict mutated during iteration
Problem
Error:
RuntimeError: OrderedDict mutated during iteration
File "C:\odoo14c\server\odoo\service\server.py", line 408, in cron_thread
for db_name, registry in registries.d.items():
Root Cause
The cron thread was iterating directly over registries.d.items() (an OrderedDict). When multiple threads are running:
- Thread A iterates over the registries
- Thread B adds/removes a database registry during the iteration
- Python raises
RuntimeErrorbecause the dictionary was modified during iteration
This is a race condition that occurs when:
- Multiple cron threads are polling for jobs
- New database connections are being created/destroyed
- Module upgrades are happening
Solution
Changed the iteration from:
for db_name, registry in registries.d.items():
To:
for db_name, registry in list(registries.d.items()):
Why this works:
list(registries.d.items())creates a snapshot of the dictionary items at that moment- We iterate over the snapshot, not the live dictionary
- Changes to the original dictionary don't affect our iteration
- This is a standard Python pattern for safe dictionary iteration
File Changed
C:\odoo14c\server\odoo\service\server.py(line 408)
Impact
- ✅ Fixes the RuntimeError during cron execution
- ✅ Allows safe concurrent access to registry dictionary
- ✅ No performance impact (the list is created very quickly)
- ✅ Standard Python best practice for this scenario
Testing
After this fix, the Odoo server should start and run without the RuntimeError. The cron threads will continue to poll for jobs safely even when database registries are being added/removed.
Restart Odoo to apply the fix:
# Stop current Odoo process and restart
python C:\odoo14c\server\odoo-bin -c C:\addon14\odoo.conf
Date
Fixed on: March 4, 2026