From d5ed04eb1582058e5d2aaf47a62ce27cc55b9d35 Mon Sep 17 00:00:00 2001 From: Louis-David Perron <100434291+perronld@users.noreply.github.com> Date: Wed, 15 Nov 2023 16:52:15 -0500 Subject: [PATCH] Woraround for registry resolving when restarting celery prefork workers --- weaver/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/weaver/utils.py b/weaver/utils.py index e9b7aec0b..9018e3d62 100644 --- a/weaver/utils.py +++ b/weaver/utils.py @@ -35,6 +35,7 @@ from bs4 import BeautifulSoup from celery.app import Celery from mypy_boto3_s3.literals import RegionName +from pyramid_celery import celery_app as app from pyramid.config import Configurator from pyramid.exceptions import ConfigurationError from pyramid.httpexceptions import ( @@ -47,7 +48,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 +from pyramid.threadlocal import get_current_registry, get_current_request from pyramid_beaker import set_cache_regions_from_settings from requests import HTTPError as RequestsHTTPError, Response from requests.structures import CaseInsensitiveDict @@ -469,7 +470,10 @@ def get_registry(container=None, nothrow=False): if isinstance(container, Registry): return container if isinstance(container, WerkzeugRequest) or container is None: - return get_current_registry() + if get_current_request() is None: + return get_registry(app) + else: + return get_current_registry() if nothrow: return None raise TypeError(f"Could not retrieve registry from container object of type [{fully_qualified_name(container)}].")