Merge lp:~hbrunn/ocb-addons/6.1-knowledge_attachment_create_fix_duplicate_check into lp:ocb-addons/6.1

Proposed by Holger Brunn (Therp)
Status: Needs review
Proposed branch: lp:~hbrunn/ocb-addons/6.1-knowledge_attachment_create_fix_duplicate_check
Merge into: lp:ocb-addons/6.1
Diff against target: 32 lines (+9/-8)
1 file modified
document/document.py (+9/-8)
To merge this branch: bzr merge lp:~hbrunn/ocb-addons/6.1-knowledge_attachment_create_fix_duplicate_check
Reviewer Review Type Date Requested Status
Ronald Portier (Therp) Approve
Review via email: mp+285359@code.launchpad.net
To post a comment you must log in.
6850. By Holger Brunn (Therp)

[FIX] don't return True as id

6851. By Holger Brunn (Therp)

[FIX] syntax

6852. By Holger Brunn (Therp)

[FIX] fix what this branch is actually intended to fix

Revision history for this message
Ronald Portier (Therp) (rportier1962) wrote :

In the if with the check_duplication, maybe first test the values, because the method call to check_duplication makes no sense if they are not filled.

Do I understand correctly that a create is turned into a write if records are found that are not duplicate according to the check, but that share the same resource and datas_fname?

review: Needs Fixing
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

check_duplication takes care for missing values itself, so I don't think we need a new branch for that.

And yes, that's what happens, which is quite broken in my opinion. But well, with this patch, it's less broken.

Revision history for this message
Ronald Portier (Therp) (rportier1962) wrote :

I was just thinking of saving a method call, I have seen that check_duplication does not break on missing values. (But is will do a nonsensical search).

Not blocking for me.

review: Approve

Unmerged revisions

6852. By Holger Brunn (Therp)

[FIX] fix what this branch is actually intended to fix

6851. By Holger Brunn (Therp)

[FIX] syntax

6850. By Holger Brunn (Therp)

[FIX] don't return True as id

6849. By Holger Brunn (Therp)

[FIX] don't choke on missing res_id, fix logic

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'document/document.py'
2--- document/document.py 2013-09-10 15:12:35 +0000
3+++ document/document.py 2016-02-08 16:40:45 +0000
4@@ -293,20 +293,21 @@
5 else:
6 if vals.get('file_size'):
7 del vals['file_size']
8- result = self._check_duplication(cr, uid, vals)
9- if not result:
10+ result = False
11+ if not self._check_duplication(cr, uid, vals) and vals.get('res_id')\
12+ and vals.get('res_model') and vals.get('datas_fname'):
13 domain = [
14 ('res_id', '=', vals['res_id']),
15 ('res_model', '=', vals['res_model']),
16 ('datas_fname', '=', vals['datas_fname']),
17 ]
18 attach_ids = self.search(cr, uid, domain, context=context)
19- super(document_file, self).write(cr, uid, attach_ids,
20- {'datas' : vals['datas']},
21- context=context)
22- result = attach_ids[0]
23- else:
24- #raise osv.except_osv(_('ValidateError'), _('File name must be unique!'))
25+ if attach_ids:
26+ super(document_file, self).write(cr, uid, attach_ids,
27+ {'datas' : vals['datas']},
28+ context=context)
29+ result = attach_ids[0]
30+ if not result:
31 result = super(document_file, self).create(cr, uid, vals, context)
32 return result
33

Subscribers

People subscribed via source and target branches