From ab1b834164d79d00935fdb2d902d146c951aa4d2 Mon Sep 17 00:00:00 2001 From: Louis-David Perron <100434291+perronld@users.noreply.github.com> Date: Mon, 20 Nov 2023 14:51:41 -0500 Subject: [PATCH] Replaced get_current_request by sys.argv to detect celery worker presence --- weaver/utils.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/weaver/utils.py b/weaver/utils.py index 346ea97d9..55308b71a 100644 --- a/weaver/utils.py +++ b/weaver/utils.py @@ -47,7 +47,7 @@ from pyramid.request import Request as PyramidRequest from pyramid.response import _guess_type as guess_file_contents # noqa: W0212 from pyramid.settings import asbool, aslist -from pyramid.threadlocal import get_current_registry, get_current_request +from pyramid.threadlocal import get_current_registry from pyramid_beaker import set_cache_regions_from_settings from pyramid_celery import celery_app as app from requests import HTTPError as RequestsHTTPError, Response @@ -469,11 +469,10 @@ def get_registry(container=None, nothrow=False): return container.registry if isinstance(container, Registry): return container + if container is None and sys.argv[0].rsplit("/", 1)[-1] == "celery": + return app.conf.get("PYRAMID_REGISTRY", {}) if isinstance(container, WerkzeugRequest) or container is None: - if get_current_request() is None: - return get_registry(app) - else: - return get_current_registry() + return get_current_registry() if nothrow: return None raise TypeError(f"Could not retrieve registry from container object of type [{fully_qualified_name(container)}].")