Use context manager to avoid open files

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-05-14 02:31:02 -04:00
parent 3a623ee416
commit c59f35225c

View File

@@ -175,7 +175,8 @@ class DocumentVersion(models.Model):
logger.debug('Intermidiate file "%s" not found.', cache_filename)
try:
converter = get_converter_class()(file_object=self.open())
with self.open() as version_file_object:
converter = get_converter_class()(file_object=version_file_object)
with converter.to_pdf() as pdf_file_object:
# Since open "wb+" doesn't create files, check if the file