Skip to content

Commit

Permalink
fix bug NoneType object has no attribute push (#2403)
Browse files Browse the repository at this point in the history
* fix bug NoneType object has no attribute push

the bug was raised by Celery and succeeded the bug ParsedInstance DoesNotExist. The ParsedInstance was being read immediately after being created which means it was not guranteed to be available in the replica. The fix aplied is to read the created ParsedInstance from the master database

* remove whitespace

* remove trailing whitespace

* fix formatting error

* do not run webhook signal as cellery task

also revert previous changes

* remove unnecessary quotes

* fix failing test

* read instance from master db when running signl
  • Loading branch information
kelvin-muchiri authored Apr 14, 2023
1 parent 76c503c commit 405f28d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion onadata/apps/restservice/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"""
import django.dispatch
from django.conf import settings
from multidb.pinning import use_master

from onadata.apps.restservice.tasks import call_service_async
from onadata.apps.restservice.utils import call_service
from onadata.apps.logger.models.instance import Instance

ASYNC_POST_SUBMISSION_PROCESSING_ENABLED = getattr(
settings, "ASYNC_POST_SUBMISSION_PROCESSING_ENABLED", False
Expand All @@ -23,7 +26,15 @@ def call_webhooks(sender, **kwargs): # pylint: disable=unused-argument
if ASYNC_POST_SUBMISSION_PROCESSING_ENABLED:
call_service_async.apply_async(args=[instance_id], countdown=1)
else:
call_service_async(instance_id)
with use_master:
try:
instance = Instance.objects.get(pk=instance_id)
except Instance.DoesNotExist:
# if the instance has already been removed we do not send it to the
# service
pass
else:
call_service(instance)


trigger_webhook.connect(call_webhooks, dispatch_uid="call_webhooks")

0 comments on commit 405f28d

Please sign in to comment.