I have a custom signal and there is a classmethod
which updates some objects where I need this signal to be disconnected so changes are not synced to pipedrive because this method is used only by a view for webhooks.
@classmethod
def backsync_all_stages(cls):
s = sync_object.disconnect(sync_object_receiver)
stages_json = PipeDriveWrapper.get_all_stages()
if stages_json.get('success'):
And there is a view which calls this method if request is POST
:
def post(self,request,*args,**kwargs):
data = json.loads(request.body)
model_alias = data['meta']['object']
Model = PipedriveSync.WEBHOOK_MODEL_MAP[model_alias]
if Model == LeadStage:
PipedriveSync.backsync_all_stages()
...
The problem is that sometimes it disconnects the signal and sometimes it doesn't. When I call PipedriveSync.backsync_all_stages()
inside shell_plus, it works correctly.
But according to view - I see in debugger that in both cases, the method is called from the same view. I absolutely don't understand what is happening.
So I invoke the webhook and set breakpoint under the disconnect
command so you can see it returns True
and traceback.
So invoking the webhook and waiting...
You can clearly see that the method is called from view and that signal wasn't disconnected (returned False
).
Meanwhile there was probably a couple of another posts since the webhook sends multiple requests. So I switch to Thread-8
in debugger. There I see that signal was disconnected properly.
The traceback is the same so why it's once True
and another time False
? This problem causes cycling through Webhook -> Client -> Webhook -> Client....
I noticed that everytime I call this method through shell_plus
, the signal is correctly disconnected.
Do you have any ideas?