abhishek-ram/django-pyas2

Sending async MDN's fails and stops working when a read fails on an object

Closed this issue · 4 comments

Have a regular job running to send async MDNs. However, the job fails, if the latest entry is faulty and all subsequent MDN's will not be sent anymore.

In order to handle this, I suggest to catch exception, try to update the record with error and process to the next one.

Folllowing error is raised:

Traceback (most recent call last):
File "manage.py", line 22, in
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/init.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.7/site-packages/django/core/management/init.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.7/site-packages/pyas2/management/commands/manageas2server.py", line 114, in handle
data=pending_mdn.payload.read(),
File "/usr/local/lib/python3.7/site-packages/django/core/files/utils.py", line 16, in
read = property(lambda self: self.file.read)
File "/usr/local/lib/python3.7/site-packages/django/db/models/fields/files.py", line 41, in _get_file
self._require_file()
File "/usr/local/lib/python3.7/site-packages/django/db/models/fields/files.py", line 38, in _require_file
raise ValueError("The '%s' attribute has no file associated with it." % self.field.name)
ValueError: The 'payload' attribute has no file associated with it.

Yes that is true but the large issue seems to be this error which is not expected. Do you have any idea how an MDN with empty payload got generated?

@abhishek-ram : Last year, this happened twice and I could not identify this for sure. Only suspicion I have is, because it is run in a Kubernetes environment, the shut-down grace period of the container was not considered to finalize the job properly: MDN created, container stoped before payload was saved. This grace period was extended and I did not have this case anymore.

@abhishek-ram : Just a follow up on this. The cases have increased and shown up in other areas as well which led me to think that DB connections dropped in mid-process. I therefore switched config settings to: 'ATOMIC_REQUESTS': True which resolved the issue in most cases.

I still have an issue when a partner sends me ASYNC MDN's for which I don't have a message for. Maybe management command messages are not affected by atomic request handling or something else. I'll review at some point, but currently no capacity for that.

Yes, the ATOMIC_REQUESTS is only applicable to Views. We would need to manually put the command inside a transaction