This PR implements https://github.com/celery/django-celery-results/issues/119 in a slightly different way. It adds retry logic only for django.db.utils.InterfaceError and psycopg2.InterfaceError, which can be errors like "connection already closed".
This method is called when an exception is raised in _store_result() and always_retry / result_backend_always_retry is set to True. If the exception is an InterfaceError, the connection is closed as a side effect of calling exception_safe_to_retry().
Then the retry logic implemented in the parent class continues, and Django will automatically open a new connection for the next attempt to store the task result or get the task metadata.
This PR implements https://github.com/celery/django-celery-results/issues/119 in a slightly different way. It adds retry logic only for django.db.utils.InterfaceError and psycopg2.InterfaceError, which can be errors like "connection already closed".
It does not retry any DatabaseError, which can be errors like "numeric value out of range" or "foreign key check failed". See https://www.psycopg.org/docs/module.html#exceptions for more info.
exception_safe_to_retry() is overridden from the parent class: https://docs.celeryproject.org/en/stable/_modules/celery/backends/base.html#BaseBackend
This method is called when an exception is raised in _store_result() and always_retry / result_backend_always_retry is set to True. If the exception is an InterfaceError, the connection is closed as a side effect of calling exception_safe_to_retry().
Then the retry logic implemented in the parent class continues, and Django will automatically open a new connection for the next attempt to store the task result or get the task metadata.