Skip to content

Commit

Permalink
Replaced get_current_request by sys.argv to detect celery worker pres…
Browse files Browse the repository at this point in the history
…ence
  • Loading branch information
perronld committed Nov 20, 2023
1 parent d85cf99 commit ab1b834
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions weaver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)}].")
Expand Down

0 comments on commit ab1b834

Please sign in to comment.