diff --git a/eox_tenant/signals.py b/eox_tenant/signals.py index adac1a21..298545b7 100644 --- a/eox_tenant/signals.py +++ b/eox_tenant/signals.py @@ -232,6 +232,7 @@ def tenant_context_addition(sender, body, headers, *args, **kwargs): # pylint: get_host_func = AsyncTaskHandler().get_host_from_task(sender) headers['eox_tenant_sender'] = get_host_func(body) + body[1]['eox_tenant_sender'] = get_host_func(body) # body = (args, kwargs, Mapping embed) def start_async_lms_tenant(sender, *args, **kwargs): # pylint: disable=unused-argument @@ -262,6 +263,7 @@ def _start_async_tenant(sender, config_key): context = sender.request headers = context.get('headers') or {} http_host = headers.get('eox_tenant_sender') + http_host = context.get('kwargs', {}).pop('eox_tenant_sender', http_host) if not http_host: # Reset settings in case of no tenant. LOG.warning("Could not find the host information for eox_tenant.signals. ") diff --git a/eox_tenant/test/test_signals.py b/eox_tenant/test/test_signals.py index a655423a..25fe6b39 100644 --- a/eox_tenant/test/test_signals.py +++ b/eox_tenant/test/test_signals.py @@ -300,9 +300,9 @@ class CeleryReceiverCLISyncTests(TestCase): def setUp(self): """ setup """ - self.body = { - 'kwargs': {}, - } + args = [] + kwargs = {} # This is the default value for kwargs + self.body = (args, kwargs) for number in range(3): Site.objects.create( domain=f"tenant{number}.com", @@ -354,9 +354,10 @@ def test_sync_process_with_tenant(self): When the task is called from a sync proccess it is used the value of the 'host' key in the request dict. """ headers = {} - body = { - 'kwargs': {}, - } + args = [] + kwargs = {} + body = (args, kwargs) + with self.settings(EDNX_TENANT_DOMAIN="some.tenant.com"): tenant_context_addition("some.task", headers=headers, body=body)