django-afip icon indicating copy to clipboard operation
django-afip copied to clipboard

Error en el formulario de TaxPayer en referencia a certificate

Open gusarg81 opened this issue 2 years ago • 6 comments

No estoy seguro si yo estoy cometiendo un error acá, pero como en cualquier formulario donde exista FILES, no tengo este tipo de errores al guardar (haya o no modificado el formulario).

Sin embargo en el formulario de TaxPayer que utilizo (nada custom, directo con ModelForm), al aplicar save() en el view (por más que no haya cambios en dicho formulario), me arroja:

Traceback (most recent call last): File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/gustavo/Desarrollo/Web/eBiller/ebiller/apps/management/views_settings.py", line 130, in settings_taxpayer_admin taxpayer = taxpayer_form.save() File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/forms/models.py", line 548, in save self.instance.save() File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/db/models/base.py", line 812, in save self.save_base( File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/db/models/base.py", line 847, in save_base pre_save.send( File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 176, in send return [ File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 177, in (receiver, receiver(signal=self, sender=sender, **named)) File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django_afip/signals.py", line 11, in update_certificate_expiration instance.certificate_expiration = instance.get_certificate_expiration() File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django_afip/models.py", line 423, in get_certificate_expiration cert = self.certificate_object File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django_afip/models.py", line 412, in certificate_object self.certificate.seek(0) File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/core/files/utils.py", line 46, in seek = property(lambda self: self.file.seek) File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/db/models/fields/files.py", line 47, in _get_file self._file = self.storage.open(self.name, "rb") File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/core/files/storage.py", line 40, in open return self._open(name, mode) File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/core/files/storage.py", line 276, in _open return File(open(self.path(name), mode)) FileNotFoundError: [Errno 2] No such file or directory: '/home/gustavo/Desarrollo/Web/eBiller/ebiller/media/eBiller.crt'

El tema acá, más allá de que no estoy seguro por qué el error, es que la ruta del certificado es incorrecto acorde a lo que arroja la excepción FileNotFoundError (cuando en realidad es "/home/gustavo/Desarrollo/Web/eBiller/ebiller/media/afip/taxpayers/certs/eBiller.crt").

¿Qué estoy haciendo mal? ¿Mejor detectar los cambios de este formulario al guardar?

gusarg81 avatar Dec 20 '22 12:12 gusarg81

Hay un signal pre_save que actualiza la columna con la fecha de vencimiento al guardar.

No estoy muy seguro por que el path es incorrecto. Estoy usando taxpayer.certificate.read (eg: el abrir el archivo está delegado a Django) Usando esto directamente te lee bien el archivo o da error también?

Estoy sin PC unos días, así que no puedo testear mucho al respecto.

On Tue, 20 Dec 2022, at 13:07, Gustavo A. Díaz wrote:

No estoy seguro si yo estoy cometiendo un error acá, pero como en cualquier formulario donde exista FILES, no tengo este tipo de errores al guardar (haya o no modificado el formulario).

Sin embargo en el formulario de TaxPayer que utilizo (nada custom, directo con ModelForm), al aplicar save() en el view (por más que no haya cambios en dicho formulario), me arroja:

Traceback (most recent call last): File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/gustavo/Desarrollo/Web/eBiller/ebiller/apps/management/views_settings.py", line 130, in settings_taxpayer_admin taxpayer = taxpayer_form.save() File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/forms/models.py", line 548, in save self.instance.save() File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/db/models/base.py", line 812, in save self.save_base( File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/db/models/base.py", line 847, in save_base pre_save.send( File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 176, in send return [ File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 177, in (receiver, receiver(signal=self, sender=sender, **named)) File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django_afip/signals.py", line 11, in update_certificate_expiration instance.certificate_expiration = instance.get_certificate_expiration() File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django_afip/models.py", line 423, in get_certificate_expiration cert = self.certificate_object File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django_afip/models.py", line 412, in certificate_object self.certificate.seek(0) File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/core/files/utils.py", line 46, in seek = property(lambda self: self.file.seek) File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/db/models/fields/files.py", line 47, in _get_file self._file = self.storage.open(self.name, "rb") File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/core/files/storage.py", line 40, in open return self._open(name, mode) File "/home/gustavo/Desarrollo/Web/eBiller/venv/lib/python3.10/site-packages/django/core/files/storage.py", line 276, in _open return File(open(self.path(name), mode)) FileNotFoundError: [Errno 2] No such file or directory: '/home/gustavo/Desarrollo/Web/eBiller/ebiller/media/eBiller.crt'

El tema acá, más allá de que no estoy seguro por qué el error, es que la ruta del certificado es incorrecto acorde a lo que arroja la excepción FileNotFoundError (cuando en realidad es "/home/gustavo/Desarrollo/Web/eBiller/ebiller/media/afip/taxpayers/certs/eBiller.crt").

¿Qué estoy haciendo mal? ¿Mejor detectar los cambios de este formulario al guardar?

— Reply to this email directly, view it on GitHub https://github.com/WhyNotHugo/django-afip/issues/173, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFSNO5IN6LOHKJSC3XLT7DWOGOR5ANCNFSM6AAAAAATENS4SM. You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Hugo

WhyNotHugo avatar Dec 20 '22 12:12 WhyNotHugo

Con taxpayer.certificate.read() no me dá ese error.

gusarg81 avatar Dec 20 '22 17:12 gusarg81

Y taxpayer.certificate.seek(0) ?

On Tue, 20 Dec 2022, at 18:19, Gustavo A. Díaz wrote:

Con taxpayer.certificate.read() no me dá ese error.

— Reply to this email directly, view it on GitHub https://github.com/WhyNotHugo/django-afip/issues/173#issuecomment-1359826169, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFSNOYO2HJWU72RGXNCSILWOHTBPANCNFSM6AAAAAATENS4SM. You are receiving this because you commented.Message ID: @.***>

-- Hugo

WhyNotHugo avatar Dec 20 '22 17:12 WhyNotHugo

Sin errores (devuelve 0).

gusarg81 avatar Dec 20 '22 17:12 gusarg81

Hasta no tener una PC no puedo verlo en más detalle y no se me ocurre nada obvio.

Te recomiendo deshabilitar el Signal provisionalmente si esto te esta bloqueando

https://docs.djangoproject.com/en/4.1/topics/signals/#django.dispatch.Signal.disconnect

On Tue, 20 Dec 2022, at 18:29, Gustavo A. Díaz wrote:

Sin errores (devuelve 0).

— Reply to this email directly, view it on GitHub https://github.com/WhyNotHugo/django-afip/issues/173#issuecomment-1359870624, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFSNO3JBTLGRSDBOFX544LWOHUGZANCNFSM6AAAAAATENS4SM. You are receiving this because you commented.Message ID: @.***>

-- Hugo

WhyNotHugo avatar Dec 20 '22 18:12 WhyNotHugo

Nada grave en realidad, no creo tener que modificar un dato de ese formulario (salvo cuando se tenga que cambiar el Logo que está dentro del mismo formulario, sino lo separo).

Chas gracias por el tip.

EDIT: desconectando el Signal, vá bien.

gusarg81 avatar Dec 20 '22 18:12 gusarg81