[8.0][FIX][base_export_manager] Fix "Expected singleton" bug. - #521
Conversation
If you had a field that got translated in more than 1 addon, you'd possibly get
to this error:
File "/opt/odoo/0079_ahk_openerp/oca/base_export_manager/models/ir_exports_line.py", line 105, in _compute_label
field.name)),
File "/opt/odoo/common/openerp/v8/openerp/fields.py", line 825, in __get__
record.ensure_one()
File "/opt/odoo/common/openerp/v8/openerp/models.py", line 5355, in ensure_one
raise except_orm("ValueError", "Expected singleton: %s" % self)
except_orm: ('ValueError', 'Expected singleton: ir.translation(4899, 703976)')
With this patch, now we let Odoo return the translated string by using its
standard method to do so, so we have to care for less.
|
Please could somebody forward-patch this to v9 when merged? Or do I open a separate PR? |
This makes the whole installation to be able to roll back if something goes wrong, instead of entering an error loop.
|
Before 9ef4280, if you had a buggy record in database, you got an endless error loop. Now you get this beautiful message: I considered adding a backup column of |
| char field with stored values. We have to inverse it to avoid database | ||
| inconsistencies. | ||
| """ | ||
| env = api.Environment(cr, SUPERUSER_ID, dict()) |
There was a problem hiding this comment.
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
|
One thing I'm facing: can it be that the textual representation of the fields (field |
| result = self.env["ir.model.fields"].search( | ||
| [("name", "=", name), | ||
| ("model_id", "=", model.id)]) | ||
| try: |
There was a problem hiding this comment.
Use if not result.exists(): instead
77dfc2c to
62e782f
Compare
92d4b2e to
dbb0416
Compare
dbb0416 to
ee91e4e
Compare
|
Just to clarify: #521 (comment) was not a bug. Is this now ready to review? |
|
Indeed it is |
|
👍 the part I haven't done |
|
@max3903 can you check this, please? |
| self.label = ("%s (%s)" % ("/".join(parts), self.name) | ||
| if parts and self.name else False) | ||
| except KeyError: | ||
| pass |
There was a problem hiding this comment.
I'd thank a little comment about why this is necessary.
There was a problem hiding this comment.
IMO it would also be a little nicer if we guarded a little closer to the key error. We could then just sub the pass for a return to accomplish the same effect
There was a problem hiding this comment.
I concur with @yajo: it's not obvious why the pass is needed, an explaining comment would be welcome.
|
I'm thinking that maybe a good improvement would be to give this addon its own menu item. Non-admins may want to manage this too, given what this addon ultimately does is make that task easier. Maybe it could be handled by a group setting. Not a requirement though. |
| @api.one | ||
| @api.depends("field3_id") | ||
| def _compute_model4_id(self): | ||
| """Get the related model for the third field.""" |
|
@pedrobaeza Sorry, I missed your message. What do you want me to check? |
|
Well, the idea is to see the improvements and give your bless. |
|
👍 LGTM |
|
Functionaly tested 👍 |
|
|
||
| @api.multi | ||
| @api.depends("field1_id", "field2_id", "field3_id") | ||
| @api.one |
There was a problem hiding this comment.
Isn't best to leave api.maulti here, since we have confirmation that Odoo intends to deprecated api.one ?
There was a problem hiding this comment.
I prefer @api.one while it exists. And I repeat that it's still not clear that it will be deprecated.
There was a problem hiding this comment.
I don't see the point for the extra work when doing the port to v9.
And when asking to reconsider deprecation, all comments I had were against keeping it. So I don't see must space for any hopes on that.
There was a problem hiding this comment.
No, there's no work needed. @api.one is still in v9, v10, and counting.
There was a problem hiding this comment.
No, they are only warnings. The PR in MQT was for removing the warning.
|
@yajo, can you attend last comments (including yours)? |
- Add some comments in complex parts. - Rename `onchange_name` to `_onchange_name` (guidelines). - Make `_compute_name`'s try block shorter and easier to understand.
|
Merging as the problem in Travis fluctuates between builds. |
[FIX][base_export_manager] Fix "Expected singleton" bug.
If you had a field that got translated in more than 1 addon, you'd possibly getto this error:
File "/opt/odoo/0079_ahk_openerp/oca/base_export_manager/models/ir_exports_line.py", line 105, in _compute_label
field.name)),
File "/opt/odoo/common/openerp/v8/openerp/fields.py", line 825, in __get__
record.ensure_one()
File "/opt/odoo/common/openerp/v8/openerp/models.py", line 5355, in ensure_one
raise except_orm("ValueError", "Expected singleton: %s" % self)
except_orm: ('ValueError', 'Expected singleton: ir.translation(4899, 703976)')
With this patch, now we let Odoo return the translated string by using its
standard method to do so, so we have to care for less.
* Move installation outside a data file.
This makes the whole installation to be able to roll back if something goes
wrong, instead of entering an error loop.
* Include envorionment in its manager.
* Add 4th field
* Move to api.multi, refactoring some stuff.
- Add some comments in complex parts.
- Rename `onchange_name` to `_onchange_name` (guidelines).
- Make `_compute_name`'s try block shorter and easier to understand.
* Allow R/W of name directly in model.
* Update tests to cover new behaviors.
[FIX][base_export_manager] Fix "Expected singleton" bug.
If you had a field that got translated in more than 1 addon, you'd possibly getto this error:
File "/opt/odoo/0079_ahk_openerp/oca/base_export_manager/models/ir_exports_line.py", line 105, in _compute_label
field.name)),
File "/opt/odoo/common/openerp/v8/openerp/fields.py", line 825, in __get__
record.ensure_one()
File "/opt/odoo/common/openerp/v8/openerp/models.py", line 5355, in ensure_one
raise except_orm("ValueError", "Expected singleton: %s" % self)
except_orm: ('ValueError', 'Expected singleton: ir.translation(4899, 703976)')
With this patch, now we let Odoo return the translated string by using its
standard method to do so, so we have to care for less.
* Move installation outside a data file.
This makes the whole installation to be able to roll back if something goes
wrong, instead of entering an error loop.
* Include envorionment in its manager.
* Add 4th field
* Move to api.multi, refactoring some stuff.
- Add some comments in complex parts.
- Rename `onchange_name` to `_onchange_name` (guidelines).
- Make `_compute_name`'s try block shorter and easier to understand.
* Allow R/W of name directly in model.
* Update tests to cover new behaviors.
Syncing from upstream OCA/server-tools (12.0)

If you had a field that got translated in more than 1 addon, you'd possibly get
to this error:
With this patch, now we let Odoo return the translated string by using its
standard method to do so, so we have to care for less.
@Tecnativa