many2many: unique constraint missing

Bug #558658 reported by Dukai Gábor
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Medium
OpenERP's Framework R&D

Bug Description

Hi!
There is a problem with the data integrity of relations stored in many2many
fields. Currently code in OpenERP assumes that many2many relations doesn't have
duplicates (object1 is not connected to object2 more than one time). However,
those tables that store many2many relations allow the same object_id pairs get
duplicated, and when that happens, code that uses the many2many field starts to
misbehave.

Examples:
-Although the client theoretically doesn't allow this, a user managed to add
the same sales tax to a product two times. The client doesn't display the same
tax twice but the tax computing method in account.tax computes a double
amount. You can imagine, with lots of products, how difficult it is to spot this
kind of problems.
-Adding relations one-at-a-time to a many2many field with [(4, object_id)]
doesn't check if that relation has already been added or not.

IMHO if the ORM set unique(object1_id,object2_id) for the relation tables
would ensure that we are free from this kind of errors.

Revision history for this message
Albert Cervera i Areny - http://www.NaN-tic.com (albert-nan) wrote :

I think this should be solved in stable and trunk branches.

Changed in openobject-server:
importance: Undecided → High
status: New → Confirmed
Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: High → Medium
milestone: none → 6.0-rc2
Changed in openobject-server:
status: Confirmed → In Progress
Revision history for this message
Yogesh (SerpentCS) (yogesh-serpentcs) wrote :

Hello Dukai Gábor,

It has been fixed into lp:~openerp-dev/openobject-server/ysa-server-framework branch.
Revision ID: <email address hidden>
Revno: 3038

Thanks.

Changed in openobject-server:
status: In Progress → Fix Committed
Changed in openobject-server:
status: Fix Committed → Confirmed
status: Confirmed → Fix Committed
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Unfortunately this cannot be merged directly, we need to also fix addons/server to avoid them trying to establish twice the same link between via a m2m, hence I'm setting back to In progress.

Changed in openobject-server:
status: Fix Committed → In Progress
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

The fix has landed in trunk with revision 3110 revision-id: <email address hidden>.

It includes both a unique SQL constraint for m2m relation tables, but also a double-check in fields.many2many.set() to avoid creating duplicate records when [(4,X)] syntax is used to write to a m2m field.

Thanks for reporting!

Note: the unique constraint will be added only in newly created databases.. otherwise it will require manual addition.

Changed in openobject-server:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.