Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The new settings from env.ini are not reloaded when I restart uwsgi, only after reboot #359

Open
uri-rodberg opened this issue Dec 21, 2021 · 3 comments

Comments

@uri-rodberg
Copy link

CACHES in settings is not defined as I expect it. Possibly a bug. Please see below.

https://stackoverflow.com/questions/70438274/how-do-i-replace-memcachedcache-with-pymemcachecache-in-django

I'm running my website on Django 3.2. I read in Django’s cache framework that MemcachedCache and python-memcached are deprecated. I installed pymemcache==3.5.0 on my staging server and changed to CACHE_URL=pymemcache://127.0.0.1:11211 in env.ini. But if I uninstall python-memcached with pip I receive an error message, that indicates that MemcachedCache is still used by my code, and it fails on import memcache.

My code uses the following imports:

from django.core.cache import cache
from django.core.cache.backends.base import DEFAULT_TIMEOUT

How do I replace MemcachedCache with PyMemcacheCache so that MemcachedCache will not be used in my code?

I'm using django-environ==0.8.1 and CACHES is defined in my settings:

CACHES = {
    'default': env.cache()
}

env is defined as environ.Env().

My Traceback:

Environment:


Request Method: GET
Request URL: https://<...>

Django Version: 3.2.10
Python Version: 3.8.12
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'crispy_forms',
 'friendship',
 'rules.apps.AutodiscoverRulesConfig',
 'sorl.thumbnail',
 'speedy.core.base',
 'speedy.core.accounts',
 'speedy.core.blocks',
 'speedy.core.uploads',
 'speedy.core.messages',
 'speedy.core.profiles',
 'speedy.core.friends',
 'speedy.core.about',
 'speedy.core.privacy',
 'speedy.core.terms',
 'speedy.net.accounts',
 'speedy.match.accounts',
 'speedy.match.likes',
 'speedy.composer.accounts',
 'speedy.mail.accounts',
 'speedy.core.contact_by_form',
 'speedy.match.profiles',
 'speedy.match.matches']
Installed Middleware:
['speedy.core.base.middleware.SessionCookieDomainMiddleware',
 'speedy.core.base.middleware.RemoveExtraSlashesMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.contrib.sites.middleware.CurrentSiteMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'speedy.core.base.middleware.LocaleDomainMiddleware',
 'speedy.core.base.middleware.EnsureCachesMiddleware',
 'speedy.core.base.middleware.UpdateSessionAuthHashMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'speedy.core.accounts.middleware.SiteProfileMiddleware']



Traceback (most recent call last):
  File "<...>/env/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "<...>/./speedy/core/base/middleware.py", line 139, in __call__
    block_managers.ensure_caches(user=request.user)
  File "<...>/./speedy/core/blocks/managers.py", line 46, in ensure_caches
    blocked_entities = cache_manager.cache_get(blocked_key, sliding_timeout=DEFAULT_TIMEOUT)
  File "<...>/./speedy/core/base/cache_manager.py", line 21, in cache_get
    wrapped_value = cache.get(key, default=DEFAULT_VALUE, version=version)
  File "<...>/env/lib/python3.8/site-packages/django/utils/connection.py", line 15, in __getattr__
    return getattr(self._connections[self._alias], item)
  File "<...>/env/lib/python3.8/site-packages/django/utils/connection.py", line 62, in __getitem__
    conn = self.create_connection(alias)
  File "<...>/env/lib/python3.8/site-packages/django/core/cache/__init__.py", line 44, in create_connection
    return backend_cls(location, params)
  File "<...>/env/lib/python3.8/site-packages/django/core/cache/backends/memcached.py", line 181, in __init__
    import memcache

Exception Type: ModuleNotFoundError at /matches/
Exception Value: No module named 'memcache'

My repository: https://github.com/speedy-net/speedy-net

Update: I checked the email message I received for debugging and I see that the CACHES in settings is equal to {'default': {'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', 'LOCATION': '127.0.0.1:11211'}}.

@uri-rodberg
Copy link
Author

I don't know why, but the way I restarted my server during deploy doesn't refresh env.ini, and the server remembers the old settings. If I restart my server with sudo reboot, with the same settings, then CACHES is equal to {'default': {'BACKEND': 'django.core.cache.backends.memcached.PyMemcacheCache', 'LOCATION': '127.0.0.1:11211'}} and the site works properly. And I confirmed that if I put dummy values in env.ini then the site doesn't work at all. But only if I restart my server with sudo reboot.

Is it a bug in django-environ that the server remembers the old env.ini settings after restarting only uwsgi?

@uri-rodberg uri-rodberg changed the title How do I replace MemcachedCache with PyMemcacheCache in Django? The new settings from env.ini are not reloaded when I restart uwsgi, only after reboot Dec 22, 2021
@fertek
Copy link

fertek commented Dec 23, 2021

Possible duplicate of #103.

@duwensi-bgi
Copy link

Please refer to #issuecomment-1518665193 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants