Skip to content

Commit 26b1f79

Browse files
alexzhangsclaude
andauthored
fix(settings): map removed memcached.MemcachedCache to PyMemcacheCache (#59)
The Django 5.2 upgrade switched the memcached driver to pymemcache, but deployments upgraded in place from Django 3.x still have SSM_CACHES_BACKEND=memcached.MemcachedCache persisted in their .ssm-env. That backend was removed in Django 4.1, so on Django 5 the manager raises InvalidCacheBackendError and fails to boot. Transparently remap the dropped alias to memcached.PyMemcacheCache (with a DeprecationWarning) so existing deployments survive the upgrade without manual .ssm-env edits. Fresh deployments should set SSM_CACHES_BACKEND=memcached.PyMemcacheCache directly. Discovered reviewing the live aiview.com hub, whose .ssm-env still carries the old backend string. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ff182ec commit 26b1f79

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

shadowsocks_manager/shadowsocks_manager/settings.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,23 @@ def __repr__(self):
297297
# Memcached
298298

299299
CACHES_BACKEND = config('SSM_CACHES_BACKEND', default='locmem.LocMemCache')
300+
301+
# Backward-compat: `memcached.MemcachedCache` (the python-memcached driver) was
302+
# removed in Django 4.1. Deployments upgraded in place from Django 3.x still have
303+
# `SSM_CACHES_BACKEND=memcached.MemcachedCache` persisted in their .ssm-env, which
304+
# would raise InvalidCacheBackendError on Django 5 and stop the manager booting.
305+
# Transparently map the dropped alias to the supported PyMemcacheCache driver so
306+
# existing deployments survive the upgrade without manual reconfiguration.
307+
if CACHES_BACKEND == 'memcached.MemcachedCache':
308+
import warnings
309+
warnings.warn(
310+
"SSM_CACHES_BACKEND=memcached.MemcachedCache was removed in Django 4.1; "
311+
"falling back to memcached.PyMemcacheCache. Set "
312+
"SSM_CACHES_BACKEND=memcached.PyMemcacheCache to silence this warning.",
313+
DeprecationWarning,
314+
)
315+
CACHES_BACKEND = 'memcached.PyMemcacheCache'
316+
300317
MEMCACHED_HOST = config('SSM_MEMCACHED_HOST', default='localhost')
301318
MEMCACHED_PORT = config('SSM_MEMCACHED_PORT', default='11211')
302319

0 commit comments

Comments
 (0)