Merge lp:~openerp-dev/openobject-server/6.0-bug-733252-xrg into lp:openobject-server/6.0

Proposed by xrg
Status: Rejected
Rejected by: Olivier Dony (Odoo)
Proposed branch: lp:~openerp-dev/openobject-server/6.0-bug-733252-xrg
Merge into: lp:openobject-server/6.0
Diff against target: 21 lines (+2/-2)
1 file modified
bin/osv/fields.py (+2/-2)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/6.0-bug-733252-xrg
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Needs Resubmitting
OpenERP buildbot (community) Approve
Review via email: mp+53015@code.launchpad.net
To post a comment you must log in.
Revision history for this message
OpenERP buildbot (openerp-buildbot) :
review: Approve
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

I would have approved, but this is a wishlist, hence it should go against trunk :-)

review: Needs Resubmitting

Unmerged revisions

3363. By xrg

osv/fields: required fields shall have ondelete="restrict" by default

Required fields have the set NOT NULL attribute. This cannot work together
with ON DELETE SET NULL behaviour for their referenced records. The
safest default seems to be ON DELETE RESTRICT.
Example: account.invoice:partner_id, which has to restrict deleting a
partner when there is any invoices linked to him/her.
This merely improves the SQL messages, from:
  IntegrityError: null value in column "partner_id" violates not-null constraint
  CONTEXT: SQL statement "UPDATE ONLY "public"."account_invoice" SET "partner_id" = NULL
      WHERE $1 OPERATOR(pg_catalog.=) "partner_id""
to:
  IntegrityError: update or delete on table "res_partner" violates foreign key
     constraint "account_invoice_partner_id_fkey" on table "account_invoice"
  DETAIL: Key (id)=(7) is still referenced from table "account_invoice".

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/osv/fields.py'
2--- bin/osv/fields.py 2011-02-01 13:07:21 +0000
3+++ bin/osv/fields.py 2011-03-11 13:28:16 +0000
4@@ -63,7 +63,7 @@
5 _symbol_set = (_symbol_c, _symbol_f)
6 _symbol_get = None
7
8- def __init__(self, string='unknown', required=False, readonly=False, domain=None, context=None, states=None, priority=0, change_default=False, size=None, ondelete="set null", translate=False, select=False, **args):
9+ def __init__(self, string='unknown', required=False, readonly=False, domain=None, context=None, states=None, priority=0, change_default=False, size=None, ondelete=None, translate=False, select=False, **args):
10 if domain is None:
11 domain = []
12 if context is None:
13@@ -76,7 +76,7 @@
14 self.help = args.get('help', '')
15 self.priority = priority
16 self.change_default = change_default
17- self.ondelete = ondelete
18+ self.ondelete = ondelete or (required and "restrict") or "set null"
19 self.translate = translate
20 self._domain = domain
21 self._context = context