HeadlinesBriefing favicon HeadlinesBriefing.com

Fix Odoo Infinite Loop in Computed Fields

DEV Community •
×

In Odoo development, infinite recomputation loops are a critical performance bottleneck, often caused by incorrectly defined computed fields. These loops occur when a field's @api.depends decorator includes the field itself, or when the compute method triggers side effects like writing to other fields or using ORM write() functions. The result is severe UI hangs, high CPU usage, and potential production crashes.

To resolve this, developers must ensure compute methods remain pure, meaning they only calculate values without modifying the database state. Dependencies must be minimal and strictly reference source fields, not the computed field itself. For UI-specific interactions, @api.onchange should be used instead of computed fields.

Additionally, storing computed values with store=True should be reserved strictly for fields used in search or grouping operations. Adhering to these architectural best practices ensures stable, scalable Odoo applications.