You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 29, 2025. It is now read-only.
We faced a strange problem. Some of the queries inside of some views that are not decorated with the @use_slave were getting routed to the slave db instances.
After a couple of hours spent debugging found the reproduction routine.
Reproduce
Consider:
@use_slavedefv1(request, *args, **kwargs):
raiseException('!')
...
defv2(request, *args, **kwargs):
print(Model2.objects.all()) # <--- Routed to the slave
...
Decorators are using ReplicationMiddleware but ReplicationMiddleware is not implementing process_exception and if the exception is not handled, the ReplicationMiddleware#process_response and routers.reset() are not called at all. Hence, the _context on the router remains dirty.
So any v2 call that is happening after the v1 raising an exception get routed to the slave instances.
Fix
Just wrapped the django_replicated decorator just like: