octue / octue-sdk-python

The python SDK for @Octue services and digital twins.
https://octue.com
Other
9 stars 3 forks source link

Are exceptions sent to the parent twice? #626

Open cortadocodes opened 5 months ago

cortadocodes commented 5 months ago

Bug report

What is the current behavior?

Service.send_exception is possibly called in both answer_pub_sub_question and Service.answer if an error is raised during question is being answered. We should find out whether exception messages are in fact being sent to the parent twice.

What is the expected behavior?

Exception messages should be sent once only.

Proposed Solution

Possibly eliminate one of the calls of the method.

cortadocodes commented 5 months ago

We previously had this code in a django-twined private app that would be triggered if a result message was received but the child then raised an exception:

# TODO: REFACTOR REQUEST Refactor this signal handler once exceptions from the octue service
# are correctly handled.
# Exceptions are sent from a service after the analysis has been finalised resulting in the service
# having an answer but marked failed. Don't update question status as failed if it has an answer.
@receiver(exception_received, sender=ServiceUsageEvent)
def update_question_status(sender, service_usage_event, **kwargs):
    logger.info("Exception received for question %s", service_usage_event.question_id)
    question = service_usage_event.question.as_subclass()

    # check to prevent completed questions with answer being set to failed
    # due to an exception being sent after the answers have been finalised.
    if not question.output_values:
        question.calculation_status = ERROR_STATUS
        question.save()