From: Johannes Holmberg Date: Wed, 8 Feb 2012 01:12:50 +0000 (+0100) Subject: Rename the BACKENDS cache to keep get_backends from discovering it. X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=5b63805c5808f27b89e4175c88a6b0a61e22b3af;p=django-social-auth.git Rename the BACKENDS cache to keep get_backends from discovering it. --- diff --git a/social_auth/backends/__init__.py b/social_auth/backends/__init__.py index fff8c30..394f74b 100644 --- a/social_auth/backends/__init__.py +++ b/social_auth/backends/__init__.py @@ -638,11 +638,11 @@ if setting('SOCIAL_AUTH_IMPORT_BACKENDS'): warn("SOCIAL_AUTH_IMPORT_SOURCES is deprecated") # Cache for discovered backends. -BACKENDS = {} +BACKENDSCACHE = {} def get_backends(force_load=False): """ - Entry point to the BACKENDS cache. If BACKENDS hasn't been + Entry point to the BACKENDS cache. If BACKENDSCACHE hasn't been populated, each of the modules referenced in AUTHENTICATION_BACKENDS is imported and checked for a BACKENDS definition and if enabled, added to the cache. @@ -659,18 +659,18 @@ def get_backends(force_load=False): A force_load boolean arg is also provided so that get_backend below can retry a requested backend that may not yet be discovered. """ - if not BACKENDS or force_load: + if not BACKENDSCACHE or force_load: for auth_backend in setting('AUTHENTICATION_BACKENDS'): module = import_module(auth_backend.rsplit(".", 1)[0]) backends = getattr(module, "BACKENDS", {}) for name, backend in backends.items(): if backend.enabled(): - BACKENDS[name] = backend - return BACKENDS + BACKENDSCACHE[name] = backend + return BACKENDSCACHE def get_backend(name, *args, **kwargs): - """Returns a backend by name. Backends are stored in the BACKENDS + """Returns a backend by name. Backends are stored in the BACKENDSCACHE cache dict. If not found, each of the modules referenced in AUTHENTICATION_BACKENDS is imported and checked for a BACKENDS definition. If the named backend is found in the module's BACKENDS @@ -678,12 +678,12 @@ def get_backend(name, *args, **kwargs): """ try: # Cached backend which has previously been discovered. - return BACKENDS[name](*args, **kwargs) + return BACKENDSCACHE[name](*args, **kwargs) except KeyError: # Force a reload of BACKENDS to ensure a missing # backend hasn't been missed. get_backends(force_load=True) try: - return BACKENDS[name](*args, **kwargs) + return BACKENDSCACHE[name](*args, **kwargs) except KeyError: return None