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

Django 3.2 cache compatibility #116

Closed
wamberg opened this issue Apr 6, 2021 · 9 comments
Closed

Django 3.2 cache compatibility #116

wamberg opened this issue Apr 6, 2021 · 9 comments

Comments

@wamberg
Copy link

wamberg commented Apr 6, 2021

While using Django 3.2, dbtemplates throws the following error:

ImportError: cannot import name '_create_cache' from 'django.core.cache'

The error stems from dbtemplates cache wrapper:

from django.core.cache import _create_cache

Side note of gratitude, this library has come in very handy for us at PBS. Thank you! 🙇

@gamecat10
Copy link

gamecat10 commented Apr 6, 2021

Temporary fix:

--- ./dbtemplates/utils/cache.py.old	2021-04-06 17:18:12.741841778 +0300
+++ ./dbtemplates/utils/cache.py	2021-04-06 17:18:08.721937235 +0300
@@ -1,4 +1,5 @@
 from django.core import signals
+from django.core.cache import caches
 from django.contrib.sites.models import Site
 from django.template.defaultfilters import slugify
 
@@ -9,13 +10,7 @@
     """
     Compatibilty wrapper for getting Django's cache backend instance
     """
-    from django.core.cache import _create_cache
-    cache = _create_cache(settings.DBTEMPLATES_CACHE_BACKEND)
-    # Some caches -- python-memcached in particular -- need to do a cleanup at
-    # the end of a request cycle. If not implemented in a particular backend
-    # cache.close is a no-op
-    signals.request_finished.connect(cache.close)
-    return cache
+    return caches[settings.DBTEMPLATES_CACHE_BACKEND]

@ArnoldJudas
Copy link

ArnoldJudas commented Apr 14, 2021

my fix for support for django 3.2 without removing support for older versions
file: dbtemplates/utils/cache.py

--- 1	2021-04-14 10:54:09.984460911 +0200
+++ 2	2021-04-14 10:54:25.011612579 +0200
@@ -1,3 +1,4 @@
+import django
 from django.core import signals
 from django.contrib.sites.models import Site
 from django.template.defaultfilters import slugify
@@ -9,8 +10,12 @@
     """
     Compatibilty wrapper for getting Django's cache backend instance
     """
-    from django.core.cache import _create_cache
-    cache = _create_cache(settings.DBTEMPLATES_CACHE_BACKEND)
+    if django.VERSION[0] >= 3 and django.VERSION[1] >= 2:
+        from django.core.cache import caches
+        cache = caches.create_connection(settings.DBTEMPLATES_CACHE_BACKEND)
+    else:
+        from django.core.cache import _create_cache
+        cache = _create_cache(settings.DBTEMPLATES_CACHE_BACKEND)
     # Some caches -- python-memcached in particular -- need to do a cleanup at
     # the end of a request cycle. If not implemented in a particular backend
     # cache.close is a no-op

@jezdez
Copy link
Member

jezdez commented Jun 3, 2021

Hey all, to move this forward it's best to just open PRs that completely pass the tests.

@fjbardelli
Copy link

Please PR, the solution works fine

@wamberg
Copy link
Author

wamberg commented Jun 22, 2021

Hi @jezdez

Hey all, to move this forward it's best to just open PRs that completely pass the tests.

Please see the attached PR when you have a moment. There was an additional change for Django 3.2 compatibility other than the cache change. Tests look good on the PR 👍

blocher added a commit to HireAnEsquire/django-dbtemplates that referenced this issue Jul 30, 2021
jschrewe added a commit to KooperationsstelleGoettingen/django-dbtemplates that referenced this issue Mar 24, 2022
traverseda added a commit to traverseda/django-dbtemplates that referenced this issue May 7, 2022
@afedosenko
Copy link

Any news?

@mpasternak
Copy link
Contributor

Hi @afedosenko , I have contacted @jezdez as I need this package up and running; if @jezdez won't be able to answer, I'll create my maintained fork and keep it up as long as the original maintainers won't be available.

@mpasternak
Copy link
Contributor

.... and I'm done, even if I merged pull request #118 and broke the build because of flake8, I'm unable to fix it because it says it needs reviewer.

So either @jezdez comes back or we should move to another repo.

@hugovk
Copy link
Member

hugovk commented Aug 10, 2022

PR #118 is merged and @mpasternak was added to the project in #121 (comment) so we should be able to get a release out soon 🤞

So let's close this.

@hugovk hugovk closed this as completed Aug 10, 2022
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

8 participants