Only question I have is why the context manager is necessary.  I think it's likely the appropriate construct, but just wondering if you tried to set DB without it and and found that things didn't work.

Just saying that this is uses a fair bit of magic.  a decorator invoking a context manager to manipulate the db router.  But if it works, it works.