Bad Studio inverse field no longer takes the server down
On 19.0, a Studio one2many with an invalid inverse field name crashed the registry and even the error page, leaving the server unusable.
On 19.0, a Studio one2many with an invalid inverse field name crashed the registry and even the error page, leaving the server unusable.
| Branch | Pull request | Commit |
|---|---|---|
| 19.0 | odoo/odoo#287589 ↗ | ebd19ec56c ↗ |
| 20.0 | odoo/odoo#291009 ↗ | 90d997075c ↗ |
[FIX] core: studio crashes server when having invalid key in relational_field Current behavior: When a Studio custom One2many field has an invalid relation field (inverse) name, accessing registry.field_inverses raises KeyError. On 19.0 this also crashes error-page rendering, leaving the server unusable after closing Studio. On 18.0, it doesn't crash the server. Expected behavior: An invalid inverse name must not crash the registry or error handler; the server should stay responsive so the user can fix the field. Steps to reproduce: 1. Install sales, project with demo data 2. Create a sale order, use Studio to add a new "Lines" field (e.g. test line) 3. In the sale order, add a product that has Create on Order field (e.g. plumbing services from the demo data) > Confirm 4. Click on the smart button to go to project/task 5. Switch to Studio again, add a related field in the task, point that to Sales Order > test line 6. Activate debug mode, click on More for test line (task) 7. In properties, turn off Read only. Important here: add an invalid key for Relation Field (e.g. 'hehe') 8. Error popup shows key error. Try to close and exit out of Studio mode > Server crashes with 500 Internal Server Error Cause of the issue: - When a custom One2many field has an invalid inverse_name (set via Studio developer mode), One2many.setup_inverses accessed registry[comodel]._fields[inverse_name] without checking existence - Building the cached registry.field_inverse property then raises an uncaught KeyError and bricks the server with 500 Internal Server Error Fix: - Add a constraint on ir.model.fields so a custom One2many cannot be saved with a relation field that does not exist on the comodel - Skip a missing inverse for manual fields in setup_inverses, so databases that already store an invalid value will no longer crash opw-6479178