﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
18154	Too many open files.	eltonplima@…	Gabe Jackson	"I'm doing a migration between two applications in django, everything was going normal until I got a class that has a field of type FileField. The import function normally to a given time in the system raises the following exception:

Original exception was:

{{{
Traceback (most recent call last):
  File ""./manage.py"", line 10, in <module>
  File ""/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py"", line 443, in execute_from_command_line
  File ""/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py"", line 382, in execute
  File ""/usr/local/lib/python2.7/dist-packages/django/core/management/base.py"", line 196, in run_from_argv
  File ""/usr/local/lib/python2.7/dist-packages/django/core/management/base.py"", line 232, in execute
  File ""/home/eltonplima/workspace/ci/ci/migracao/management/commands/import_protocolo.py"", line 291, in handle
  File ""/home/eltonplima/workspace/ci/ci/migracao/management/commands/import_protocolo.py"", line 139, in protocolo_relatorio_arquivo
  File ""/home/eltonplima/workspace/ci/ci/migracao/protocolo/protocolos/models.py"", line 168, in __unicode__
  File ""/usr/local/lib/python2.7/dist-packages/django/db/models/fields/files.py"", line 46, in _get_file
  File ""/usr/local/lib/python2.7/dist-packages/django/core/files/storage.py"", line 33, in open
  File ""/usr/local/lib/python2.7/dist-packages/django/core/files/storage.py"", line 156, in _open
IOError: [Errno 24] Too many open files: u'/home/eltonplima/workspace/ci/ci/media/uploads/estado_a/municipio_a/cliente_a/2010/03_marco/arquivo.pdf'

}}}

That is, django is opening each file but is not closing, so I'm forced to close it manually, in theory django should not automatically close the file?

My code:


{{{
conversoes = ArquivoProtocolo.objects.using('protocolo').all()
if conversoes.count() > 0:
    for conversao in conversoes:
        ProtocoloRelatorioArquivo.objects.get_or_create(
         id=conversao.id,
         tipo_relatorio=TipoRelatorio.objects.get(id=conversao.tipo_relatorio.id),
         arquivo=conversao.arquivo,
         protocolo_relatorio=ProtocoloRelatorio.objects.get(id=conversao.protocolo_arquivo.id)
        )
        conversao.arquivo.close()# This should really be necessary?

}}}
"	Bug	closed	File uploads/storage	1.4	Normal	fixed			Accepted	0	1	0	0	0	0
