From 0407d73824cc4cb3669079271219383f5c743b91 Mon Sep 17 00:00:00 2001 From: Agate Date: Thu, 28 Jul 2022 11:36:29 +0200 Subject: [PATCH 3/7] Fix authentic tests under django 3.2 --- hobo/agent/authentic2/provisionning.py | 30 +++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/hobo/agent/authentic2/provisionning.py b/hobo/agent/authentic2/provisionning.py index c7c404a..255d4cc 100644 --- a/hobo/agent/authentic2/provisionning.py +++ b/hobo/agent/authentic2/provisionning.py @@ -16,6 +16,7 @@ from django.db import connection, transaction from django.urls import reverse from django.utils.encoding import force_text from django_rbac.utils import get_ou_model, get_role_model, get_role_parenting_model +from tenant_schemas.utils import tenant_context from hobo.agent.common import notify_agents from hobo.signature import sign_url @@ -368,22 +369,25 @@ class Provisionning(threading.local): if not (saved or deleted): return - t = threading.Thread(target=self.do_provision, kwargs={'saved': saved, 'deleted': deleted}) + t = threading.Thread( + target=self.do_provision, kwargs={'saved': saved, 'deleted': deleted, "tenant": connection.tenant} + ) t.start() self.threads.add(t) - def do_provision(self, saved, deleted): - try: - ous = {ou.id: ou for ou in OU.objects.all()} - self.notify_roles(ous, saved.get(Role, [])) - self.notify_roles(ous, deleted.get(Role, []), mode='deprovision') - self.notify_users(ous, saved.get(User, [])) - self.notify_users(ous, deleted.get(User, []), mode='deprovision') - except Exception: - # last step, clear everything - logger.exception(u'error in provisionning thread') - finally: - self.threads.discard(threading.current_thread()) + def do_provision(self, saved, deleted, tenant): + with tenant_context(tenant): + try: + ous = {ou.id: ou for ou in OU.objects.all()} + self.notify_roles(ous, saved.get(Role, [])) + self.notify_roles(ous, deleted.get(Role, []), mode='deprovision') + self.notify_users(ous, saved.get(User, [])) + self.notify_users(ous, deleted.get(User, []), mode='deprovision') + except Exception: + # last step, clear everything + logger.exception(u'error in provisionning thread') + finally: + self.threads.discard(threading.current_thread()) def wait(self): for thread in list(self.threads): -- 2.36.1