0

I am using a pre_save signal to store the user who performed the last operation on a particular instance.

To achieve this, I'm using a middleware. In the process_request function of it, the signal is registered with the appropriate function, set_user as shown below.

mark_who_did = curry(self.set_user, user)
models.signals.pre_save.connect(
      mark_who_did,
      dispatch_uid=(self.__class__, request,),
      weak=False
)

Then, I'm disconnecting this signal in the process_response function of the middleware.

models.signals.pre_save.disconnect(dispatch_uid=(self.__class__, request,))

This works fine when concurrency is not involved. However, suppose we have three concurrent requests - the signal is connected three times, and the set_user method is invoked nine times, for each user-request combination.

As per my understanding, each request should have been operating independently, but that is obviously not the case. Is there something I'm missing, or is there something I could change in my code to fix this?

Anomitra
  • 1,111
  • 15
  • 31

0 Answers0