From baef4d3d92501be88bed88970096cbe2219be832 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 27 Aug 2013 17:07:08 +0200 Subject: [PATCH] [FIX] Force safer ondelete=restrict on the `alias_id` _inherits FK on models with a mail.alias parent The delete-rule was initially set to `cascade` in revision 6897.16.13 revid:odo@openerp.com-20120705141706-5gm5mmqode3bvkuc because the ORM would not allow anything else for the FK of an _inherits relationship. This constraint was later lifted in 7.0 server at revision 4681 revid:odo@openerp.com-20121212210247-emrz5rf9ewcwdggu so we can now switch to the intended default behavior: when deleting mail aliases we never want to cascade delete the child records, as that could lead to unwanted deletions. On the other hand the aliases are automatically deleted when the record they belong to is deleted, as a kind of internal dependency. This is the intended safe way to delete them. There is a special case when the same alias is manually set on multiple records, in which case you will not be able to delete any of those records. This is an acceptable exception and should be manually handled if ever needed, by temporarily linking the records to delete to new dummy aliases. bzr revid: odo@openerp.com-20130827150708-62hqk8p7twd527n0 --- addons/crm/crm.py | 2 +- addons/hr_recruitment/hr_recruitment.py | 2 +- addons/mail/mail_group.py | 2 +- addons/mail/res_users.py | 2 +- addons/project/project.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index df6d5e12b66..5953500dcec 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -125,7 +125,7 @@ class crm_case_section(osv.osv): 'note': fields.text('Description'), 'working_hours': fields.float('Working Hours', digits=(16,2 )), 'stage_ids': fields.many2many('crm.case.stage', 'section_stage_rel', 'section_id', 'stage_id', 'Stages'), - 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True, + 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True, help="The email address associated with this team. New emails received will automatically " "create new leads assigned to the team."), } diff --git a/addons/hr_recruitment/hr_recruitment.py b/addons/hr_recruitment/hr_recruitment.py index 6dfc0869947..d97a6ee80ec 100644 --- a/addons/hr_recruitment/hr_recruitment.py +++ b/addons/hr_recruitment/hr_recruitment.py @@ -496,7 +496,7 @@ class hr_job(osv.osv): _inherits = {'mail.alias': 'alias_id'} _columns = { 'survey_id': fields.many2one('survey', 'Interview Form', help="Choose an interview form for this job position and you will be able to print/answer this interview from all applicants who apply for this job"), - 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True, + 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True, help="Email alias for this job position. New emails will automatically " "create new applicants for this job position."), } diff --git a/addons/mail/mail_group.py b/addons/mail/mail_group.py index 977608f487e..481109a8ebe 100644 --- a/addons/mail/mail_group.py +++ b/addons/mail/mail_group.py @@ -76,7 +76,7 @@ class mail_group(osv.Model): help="Small-sized photo of the group. It is automatically "\ "resized as a 64x64px image, with aspect ratio preserved. "\ "Use this field anywhere a small image is required."), - 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True, + 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True, help="The email address associated with this group. New emails received will automatically " "create new topics."), } diff --git a/addons/mail/res_users.py b/addons/mail/res_users.py index f7c91939b98..c6a935a62b7 100644 --- a/addons/mail/res_users.py +++ b/addons/mail/res_users.py @@ -34,7 +34,7 @@ class res_users(osv.Model): _inherits = {'mail.alias': 'alias_id'} _columns = { - 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True, + 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True, help="Email address internally associated with this user. Incoming "\ "emails will appear in the user's notifications."), } diff --git a/addons/project/project.py b/addons/project/project.py index 8ffd64e0506..d7794a02fea 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -281,7 +281,7 @@ class project(osv.osv): 'type_ids': fields.many2many('project.task.type', 'project_task_type_rel', 'project_id', 'type_id', 'Tasks Stages', states={'close':[('readonly',True)], 'cancelled':[('readonly',True)]}), 'task_count': fields.function(_task_count, type='integer', string="Open Tasks"), 'color': fields.integer('Color Index'), - 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True, + 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True, help="Internal email associated with this project. Incoming emails are automatically synchronized" "with Tasks (or optionally Issues if the Issue Tracker module is installed)."), 'alias_model': fields.selection(_alias_models, "Alias Model", select=True, required=True,