Merge lp:~camptocamp/openobject-addons/7.0-fix-1319109 into lp:openobject-addons/7.0

Proposed by Yannick Vaucher @ Camptocamp
Status: Merged
Merge reported by: Yannick Vaucher @ Camptocamp
Merged at revision: not available
Proposed branch: lp:~camptocamp/openobject-addons/7.0-fix-1319109
Merge into: lp:openobject-addons/7.0
Diff against target: 129 lines (+24/-23)
1 file modified
report_webkit/webkit_report.py (+24/-23)
To merge this branch: bzr merge lp:~camptocamp/openobject-addons/7.0-fix-1319109
Reviewer Review Type Date Requested Status
Nicolas Bessi - Camptocamp (community) no test, code review Approve
OpenERP Core Team Pending
Review via email: mp+219406@code.launchpad.net

Description of the change

Transmit parser_instance using partial function for mako translation callback. This to remove parser_instance from attribute as it can cause race condition on cursors.

To post a comment you must log in.
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Thanks to provide patch as disscussed.

Just a little
little indent
49 uid,
50 self.name2,
51 context=context)

else

LGTM

review: Approve (no test, code review)
10028. By Yannick Vaucher @ Camptocamp on 2014-05-14

fix indentation

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

https://github.com/odoo/odoo/pull/56 has been merged -> setted as Merged

Revision history for this message
Serpent Consulting Services (serpent-consulting-services) wrote :

The status of the proposal should not be 'merged'.
This is still an issue on windows!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'report_webkit/webkit_report.py'
2--- report_webkit/webkit_report.py 2014-03-24 10:17:31 +0000
3+++ report_webkit/webkit_report.py 2014-05-14 09:50:58 +0000
4@@ -37,6 +37,7 @@
5 import tempfile
6 import time
7 import logging
8+from functools import partial
9
10 from mako.template import Template
11 from mako.lookup import TemplateLookup
12@@ -68,7 +69,6 @@
13 """
14 def __init__(self, name, table, rml=False, parser=False,
15 header=True, store=False):
16- self.parser_instance = False
17 self.localcontext = {}
18 report_sxw.__init__(self, name, table, rml, parser,
19 header, store)
20@@ -189,16 +189,16 @@
21 _logger.error('cannot remove file %s: %s', f_to_del, exc)
22 return pdf
23
24- def translate_call(self, src):
25+ def translate_call(self, parser_instance, src):
26 """Translate String."""
27- ir_translation = self.pool.get('ir.translation')
28+ ir_translation = self.pool['ir.translation']
29 name = self.tmpl and 'addons/' + self.tmpl or None
30- res = ir_translation._get_source(self.parser_instance.cr, self.parser_instance.uid,
31- name, 'report', self.parser_instance.localcontext.get('lang', 'en_US'), src)
32+ res = ir_translation._get_source(parser_instance.cr, parser_instance.uid,
33+ name, 'report', parser_instance.localcontext.get('lang', 'en_US'), src)
34 if res == src:
35 # no translation defined, fallback on None (backward compatibility)
36- res = ir_translation._get_source(self.parser_instance.cr, self.parser_instance.uid,
37- None, 'report', self.parser_instance.localcontext.get('lang', 'en_US'), src)
38+ res = ir_translation._get_source(parser_instance.cr, parser_instance.uid,
39+ None, 'report', parser_instance.localcontext.get('lang', 'en_US'), src)
40 if not res :
41 return src
42 return res
43@@ -213,14 +213,14 @@
44 if report_xml.report_type != 'webkit':
45 return super(WebKitParser,self).create_single_pdf(cursor, uid, ids, data, report_xml, context=context)
46
47- self.parser_instance = self.parser(cursor,
48- uid,
49- self.name2,
50- context=context)
51+ parser_instance = self.parser(cursor,
52+ uid,
53+ self.name2,
54+ context=context)
55
56 self.pool = pooler.get_pool(cursor.dbname)
57 objs = self.getObjects(cursor, uid, ids, context)
58- self.parser_instance.set_context(objs, data, ids, report_xml.report_type)
59+ parser_instance.set_context(objs, data, ids, report_xml.report_type)
60
61 template = False
62
63@@ -250,17 +250,18 @@
64 if not css :
65 css = ''
66
67+ translate_call = partial(self.translate_call, parser_instance)
68 #default_filters=['unicode', 'entity'] can be used to set global filter
69 body_mako_tpl = mako_template(template)
70 helper = WebKitHelper(cursor, uid, report_xml.id, context)
71 if report_xml.precise_mode:
72 for obj in objs:
73- self.parser_instance.localcontext['objects'] = [obj]
74+ parser_instance.localcontext['objects'] = [obj]
75 try :
76 html = body_mako_tpl.render(helper=helper,
77 css=css,
78- _=self.translate_call,
79- **self.parser_instance.localcontext)
80+ _=translate_call,
81+ **parser_instance.localcontext)
82 htmls.append(html)
83 except Exception:
84 msg = exceptions.text_error_template().render()
85@@ -270,8 +271,8 @@
86 try :
87 html = body_mako_tpl.render(helper=helper,
88 css=css,
89- _=self.translate_call,
90- **self.parser_instance.localcontext)
91+ _=translate_call,
92+ **parser_instance.localcontext)
93 htmls.append(html)
94 except Exception:
95 msg = exceptions.text_error_template().render()
96@@ -281,9 +282,9 @@
97 try :
98 head = head_mako_tpl.render(helper=helper,
99 css=css,
100- _=self.translate_call,
101+ _=translate_call,
102 _debug=False,
103- **self.parser_instance.localcontext)
104+ **parser_instance.localcontext)
105 except Exception:
106 raise except_osv(_('Webkit render!'),
107 exceptions.text_error_template().render())
108@@ -293,8 +294,8 @@
109 try :
110 foot = foot_mako_tpl.render(helper=helper,
111 css=css,
112- _=self.translate_call,
113- **self.parser_instance.localcontext)
114+ _=translate_call,
115+ **parser_instance.localcontext)
116 except:
117 msg = exceptions.text_error_template().render()
118 _logger.error(msg)
119@@ -304,8 +305,8 @@
120 deb = head_mako_tpl.render(helper=helper,
121 css=css,
122 _debug=tools.ustr("\n".join(htmls)),
123- _=self.translate_call,
124- **self.parser_instance.localcontext)
125+ _=translate_call,
126+ **parser_instance.localcontext)
127 except Exception:
128 msg = exceptions.text_error_template().render()
129 _logger.error(msg)