Skip to content

[8.0][FIX][base_export_manager] Fix "Expected singleton" bug. - #521

Merged
pedrobaeza merged 8 commits into
OCA:8.0from
Tecnativa:8.0-base_export_manager-fix_singleton_error
Oct 18, 2016
Merged

[8.0][FIX][base_export_manager] Fix "Expected singleton" bug.#521
pedrobaeza merged 8 commits into
OCA:8.0from
Tecnativa:8.0-base_export_manager-fix_singleton_error

Conversation

@yajo

@yajo yajo commented Aug 17, 2016

Copy link
Copy Markdown
Member

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.

@Tecnativa

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.
@yajo

yajo commented Aug 17, 2016

Copy link
Copy Markdown
Member Author

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.
@yajo

yajo commented Aug 17, 2016

Copy link
Copy Markdown
Member Author

Before 9ef4280, if you had a buggy record in database, you got an endless error loop. Now you get this beautiful message:

captura de pantalla de 2016-08-17 13-40-42

I considered adding a backup column of ir.exports.line.name, but it's not necessary because now installation gets rolled back if anything fails, and it does not lose data.

Comment thread base_export_manager/hooks.py Outdated
char field with stored values. We have to inverse it to avoid database
inconsistencies.
"""
env = api.Environment(cr, SUPERUSER_ID, dict())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with api.Environment.manage():
    env = api.Environment(cr, SUPERUSER_ID, {})

@pedrobaeza

Copy link
Copy Markdown
Member

One thing I'm facing: can it be that the textual representation of the fields (field name) have changed? It seems that previously you have account_id / code for representing a sub field, and now it's account_id/code (without spaces).

result = self.env["ir.model.fields"].search(
[("name", "=", name),
("model_id", "=", model.id)])
try:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use if not result.exists(): instead

@pedrobaeza
pedrobaeza force-pushed the 8.0-base_export_manager-fix_singleton_error branch 4 times, most recently from 77dfc2c to 62e782f Compare August 18, 2016 09:31
@pedrobaeza
pedrobaeza force-pushed the 8.0-base_export_manager-fix_singleton_error branch 4 times, most recently from 92d4b2e to dbb0416 Compare August 18, 2016 10:09
@pedrobaeza
pedrobaeza force-pushed the 8.0-base_export_manager-fix_singleton_error branch from dbb0416 to ee91e4e Compare August 18, 2016 10:15
@yajo

yajo commented Aug 18, 2016

Copy link
Copy Markdown
Member Author

Just to clarify: #521 (comment) was not a bug.

Is this now ready to review?

@pedrobaeza

Copy link
Copy Markdown
Member

Indeed it is

@pedrobaeza

Copy link
Copy Markdown
Member

👍 the part I haven't done

@pedrobaeza

Copy link
Copy Markdown
Member

@max3903 can you check this, please?

self.label = ("%s (%s)" % ("/".join(parts), self.name)
if parts and self.name else False)
except KeyError:
pass

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd thank a little comment about why this is necessary.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@yajo yajo Aug 22, 2016

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea.

@dreispt dreispt Sep 16, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concur with @yajo: it's not obvious why the pass is needed, an explaining comment would be welcome.

@yajo

yajo commented Aug 18, 2016

Copy link
Copy Markdown
Member Author

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."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/third/fourth

@max3903

max3903 commented Aug 30, 2016

Copy link
Copy Markdown
Member

@pedrobaeza Sorry, I missed your message. What do you want me to check?

@pedrobaeza

Copy link
Copy Markdown
Member

Well, the idea is to see the improvements and give your bless.

@max3903 max3903 added this to the 8.0 milestone Aug 30, 2016
@max3903

max3903 commented Aug 30, 2016

Copy link
Copy Markdown
Member

👍 LGTM

@rafaelbn

Copy link
Copy Markdown
Member

Functionaly tested 👍


@api.multi
@api.depends("field1_id", "field2_id", "field3_id")
@api.one

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't best to leave api.maulti here, since we have confirmation that Odoo intends to deprecated api.one ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer @api.one while it exists. And I repeat that it's still not clear that it will be deprecated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there's no work needed. @api.one is still in v9, v10, and counting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't Lint report errors?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they are only warnings. The PR in MQT was for removing the warning.

@pedrobaeza

Copy link
Copy Markdown
Member

@yajo, can you attend last comments (including yours)?

@yajo yajo changed the title [FIX][base_export_manager] Fix "Expected singleton" bug. [8.0][FIX][base_export_manager] Fix "Expected singleton" bug. Oct 17, 2016
yajo added 3 commits October 17, 2016 14:38
- Add some comments in complex parts.
- Rename `onchange_name` to `_onchange_name` (guidelines).
- Make `_compute_name`'s try block shorter and easier to understand.
@pedrobaeza

Copy link
Copy Markdown
Member

Merging as the problem in Travis fluctuates between builds.

@pedrobaeza
pedrobaeza merged commit 76f291b into OCA:8.0 Oct 18, 2016
@pedrobaeza
pedrobaeza deleted the 8.0-base_export_manager-fix_singleton_error branch October 18, 2016 10:53
yajo added a commit to Tecnativa/server-tools that referenced this pull request Jun 21, 2017
[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.
lasley pushed a commit to LasLabs/server-tools that referenced this pull request Aug 29, 2017
[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.
SiesslPhillip pushed a commit to grueneerde/OCA-server-tools that referenced this pull request Nov 20, 2024
Syncing from upstream OCA/server-tools (12.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants