ajeebkp23 / python-relatorio

Automatically exported from code.google.com/p/python-relatorio. Thus it enables to to install this package via pip.
GNU General Public License v3.0
0 stars 0 forks source link

temporary openoffice file cannot be closed under windows #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, found a small issue with relatorio,

STR
1. Launch trytond under windows (yes, not straightforward, but not really 
difficult)
2. Launch tryton client, log in and attempt to generate a report

Expected: The report opens in OpenOffice
Real world: A 500 error is returned

trytond 3.0.2 on Windows 7 Pro 32
(the same steps on the demo server with the same windows client correctly 
generate a report)

Observations / investigation:

The temporary file cannot be removed as it is still opened. The bug
occurs at trytond/report/report.py:280 with the instruction "os.remove(path)".

Adding the line

self.inzip.close()

just after relatorio/templates/opendocument.py:890 resolved the issue.

Indeed, closing outzip in Report.parse (trytond/report/report.py:258) does not 
prevent it from being reopened when OOSerializer's __init__ is called, in 
Template.generate function at opendocument.py:710, with self._zip_source as an 
argument. self._zip_source is not the same object as Report.parse's outzip as 
it is re-created (and re-opened) from its path at opendocument.py:264.

It therefore needs to be closed at the end of the process, and a possibility is 
to make the suggested change above. You may have reasons to close self.inzip 
somewhere else, but it would hardly be possible to close it before this point.

This bug probably only occurs on Windows, which is maybe a little fussier about 
file handles not being released, and is probably not relevant for linux 
versions but it may be worth fixing it.

Original issue reported on code.google.com by thomas.k...@gmail.com on 12 Feb 2014 at 8:58

GoogleCodeExporter commented 9 years ago
Please test patch at http://codereview.appspot.com/62550043

Original comment by cedric.krier@b2ck.com on 12 Feb 2014 at 10:51

GoogleCodeExporter commented 9 years ago
Seems to work flawlessly.
Thanks for this. Indeed much more logical to open and close the file in methods 
of the same class.

Original comment by thomas.k...@gmail.com on 14 Feb 2014 at 2:38

GoogleCodeExporter commented 9 years ago
Fixes zipfile.BadZipfile: Bad magic number for file header too :-)

Thank you very much! 

Original comment by ckar...@googlemail.com on 12 Mar 2014 at 5:23

GoogleCodeExporter commented 9 years ago
Fixed with ra5047b9530f2

Original comment by cedric.krier@b2ck.com on 12 Mar 2014 at 5:36