Giter Club home page Giter Club logo

django-cacheops's People

Contributors

aykut avatar bourivouh avatar crazyzubr avatar davidfb avatar eli-schwartz avatar elmit avatar emilstenstrom avatar erthalion avatar georgepasturemap avatar ihucos avatar ir4y avatar itcrab avatar jeremystretch avatar jhillacre avatar libram avatar lokhman avatar m1ha-shvn avatar michalochman avatar mikevl avatar mjnaderi avatar mvbrn avatar nicwolff avatar prokaktus avatar ron8mcr avatar suor avatar timgates42 avatar timsavage avatar ttys15 avatar tumb1er avatar yuego avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-cacheops's Issues

Multi-table inheritance not supported

More precisely, automatic event-based doesn't work properly for it. There are actually two different cases:

  1. When SubModel instance is added, changed or deleted none of BaseModel queries invalidated.
  2. When BaseModel instance changed or deleted none of queries for any submodels are invalidated.

Error with Django 1.6

Hi, I imagine cacheops is not supposed to work with the as-yet-unreleased Django 1.6, but I thought I'd let you know what happens when I try. I get:

AttributeError at /flight/2013-07-15-05-25-1log_2/

'WhereNode' object has no attribute 'subtree_parents'

Request Method: GET
Request URL: http://afterflight.foobarbecue.com:8002/flight/2013-07-15-05-25-1log_2/
Django Version: 1.6b4
Exception Type: AttributeError
Exception Value:

'WhereNode' object has no attribute 'subtree_parents'

TypeError: object of type 'Query' has no len()

Get the following error on a offset/limit query

File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/django/db/models/query.py", line 118, in _result_iter
self._fill_cache()
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/django/db/models/query.py", line 892, in _fill_cache
self._result_cache.append(self._iter.next())
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/query.py", line 327, in iterator
self._cache_results(cache_key, results)
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/query.py", line 230, in _cache_results
cond_dnf = dnf(self)
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/utils.py", line 107, in dnf
result = _dnf(where)
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/utils.py", line 83, in _dnf
chilren_dnfs = filter(None, imap(_dnf, where.children))
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/utils.py", line 83, in _dnf
chilren_dnfs = filter(None, imap(_dnf, where.children))
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/utils.py", line 83, in _dnf
chilren_dnfs = filter(None, imap(_dnf, where.children))
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/utils.py", line 83, in _dnf
chilren_dnfs = filter(None, imap(_dnf, where.children))
File "/home/harshil/workspace/seedinvest/local/lib/python2.7/site-packages/cacheops/utils.py", line 74, in _dnf
elif lookup == 'in' and len(value) < LONG_DISJUNCTION:
TypeError: object of type 'Query' has no len()

wrong conj_keys for query in django.contrib.auth

In django.contrib.auth in model User in method get_profile()
formed query for retrieve Profile. like:

Profile.objects.get(user__id__exact=123)

its equal for query:

Profile.objects.get(user=123)

but their conj_keys is not equal:
for first query - key is "conj:profile.profile:id=123"
for second query - key is "conj:profile.profile:user_id=123"

and first key is wrong (must be "user_id=123" or something like this, but not "id=123")

used django 1.3.1 and last version of cacheops from 16.04

Проблемы валидности кеша в консольных скриптах

Кеш по каким-то причинам не инвалидируется, если запускать консольные скрипты.
Обновляю или добавляю записи, но на веб морде изменений нет. Такое впечатление, что это два разных кеша. При чем в консоли кеш даже после манипуляций не инвалидируется. И при повторном запуске скрипт фейлиться с эксепшенами. Так как пытается манипулировать с уже не существующими обьектами.
Приходится при старте скрипта инвалидировать кеш , через dbflush . Соотвественно и при его завершении. Думаю стоит протестировать, и поискать причины. Так же не очень приятно писать импорт библиотеки, что бы запустить скрипт. Все это как-то не трушно. А в целом утилита добрая))

PicklingError: Can't pickle User Groups

I have a signal removing and adding user groups.

Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/code/filterfoundry/ffprofile/views.py" in register_with_subscription_plan
  362.     return register(request, *args, **kwargs)
File "/home/code/filterfoundry/registration/views.py" in register
  187.             new_user = backend.register(request, **form.cleaned_data)
File "/home/code/filterfoundry/registration/backends/simple/__init__.py" in register
  33.                                      request=request)
File "/usr/local/lib/python2.6/dist-packages/django/dispatch/dispatcher.py" in send
  172.             response = receiver(signal=self, sender=sender, **named)
File "/home/code/filterfoundry/ffprofile/signals.py" in new_user
  71.         object.save()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py" in save
  460.         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py" in save_base
  570.                 created=(not record_exists), raw=raw, using=using)
File "/usr/local/lib/python2.6/dist-packages/django/dispatch/dispatcher.py" in send
  172.             response = receiver(signal=self, sender=sender, **named)
File "/home/code/filterfoundry/promocodes/signals.py" in new_promocode
  9.         subscription_change(instance.user,instance.code.subscription)
File "/home/code/filterfoundry/subscription/views.py" in subscription_change
  64.         user.groups.remove(old_group)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/fields/related.py" in remove
  511.                 self._remove_items(self.source_field_name, self.target_field_name, *objs)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/fields/related.py" in _remove_items
  622.                     '%s__in' % target_field_name: old_ids
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py" in delete
  444.         collector.collect(del_query)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/deletion.py" in collect
  146.                             reverse_dependency=reverse_dependency)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/deletion.py" in add
  91.         if not objs:
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py" in __nonzero__
  113.             iter(self).next()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py" in _result_iter
  107.                 self._fill_cache()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py" in _fill_cache
  772.                     self._result_cache.append(self._iter.next())
File "/home/code/filterfoundry/cacheops/query.py" in iterator
  328.             self._cache_results(cache_key, results)
File "/home/code/filterfoundry/cacheops/query.py" in _cache_results
  230.         cache_thing(self.model, cache_key, results, cond_dnf, timeout=self._cachetimeout)
File "/home/code/filterfoundry/cacheops/query.py" in cache_thing
  40.     pickled_data = pickle.dumps(data, -1)

Exception Type: PicklingError at /users/join/creative/
Exception Value: Can't pickle <class 'django.contrib.auth.models.User_groups'>: attribute lookup django.contrib.auth.models.User_groups failed

Invalidating proxy models

Hi, is there correct way to invalidate proxy model objects when changed "parent" model object ?

I have:

# tihs is parent
class Video(models.Model):
    objects = VideoManager()


# this is proxy
class OembedVideo(Video, OembedVideoMixin):
    class Meta:
        proxy = True

    objects = DefaultManager()

# fix invalidation here:
class DefaultManager(VideoManager):
    def get(self, *args, **kwargs):
        """ добиваемся того, чтобы объекты OembedVideo
        инвалидировались при изменении модели Video
        По факту это одна и также модель, 
но cacheops автоматически не инвалидирует
        объекты проксируемых моделей при изменении 
объекта родительской модели """
        from cacheops import cached_as
        @cached_as(Video.objects.get(**kwargs))
        def _get():
            qs = self.get_query_set()
            return qs.nocache().get(*args, **kwargs)

        return _get()

without manager override, when i change Video model object, OembedVideo is still returns old cache.

ORDER BY and LIMIT/OFFSET caveats

Hi,

After some research, testing and code inspection of various Django model caching alternatives (mainly projects in http://www.djangopackages.com/grids/g/caching/), we've decided to go with cacheops.

Even it sometimes seems to be too aggressive invalidating data, even I'm not a fan of replicating same serialised instances in differente Redis keys, and even I would prefer a memcache-based solution using an LRU policy for discarding old/unused cached stuff (and therefore not setting random Redis timeouts in the cacheops cfg), cacheops seems to be the most complete and transparent approach at the moment.

After some testing it seem to work smoothly, but we have found problems with invalidations when editing elements in a simple listing of users paginated and ordered by some sort criteria. Disabling ordering seems to fix the issue. Reviewing the caveats section in the documentation it seems to be related to the 'ORDER BY and LIMIT/OFFSET don't affect invalidation' item... but, could you please provide some extra information about this limitation. It's not allowed to enable cacheops on ordered QuerySets?

Thanks! :)

Watched variable changed

We're encountering the following problem with cacheops on various places in our site. It all started after we changed wsgi settings (see below) to fight memory leaks. In particular, we blame added multithreading.

Traceback (most recent call last):

  File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)

  ...

  File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 82, in __len__
    self._result_cache = list(self.iterator())

  File "/usr/lib/python2.6/site-packages/cacheops/query.py", line 327, in iterator
    self._cache_results(cache_key, results)

  File "/usr/lib/python2.6/site-packages/cacheops/query.py", line 231, in _cache_results
    cache_thing(self.model, cache_key, results, cond_dnf, timeout=self._cachetimeout)

  File "/usr/lib/python2.6/site-packages/cacheops/query.py", line 57, in cache_thing
    txn.execute()

  File "/usr/lib/python2.6/site-packages/redis/client.py", line 1515, in execute
    return execute(conn, stack)

  File "/usr/lib/python2.6/site-packages/redis/client.py", line 1465, in _execute_transaction
    raise WatchError("Watched variable changed.")

WatchError: Watched variable changed.

Here's out set up:

Apache/2.2.16
mod_wsgi/3.3
Python/2.6.7
cacheops/0.9.1

httpd.conf

WSGIDaemonProcess test processes=4 threads=15 maximum-requests=200 stack-size=1048576 display-name=%{GROUP}
WSGIProcessGroup test
WSGISocketPrefix /var/run/wsgi
WSGIRestrictEmbedded On

settings.py

CACHEOPS_REDIS = {
    'host': '127.0.0.1',
    'port': 6379,
    'db': 1,
    'socket_timeout': 3,
}

CACHEOPS = {
        '*.*': ('all', 60*15),
}

CACHES = {
    'default': {
        'BACKEND': 'redis_cache.RedisCache',
        'LOCATION': '127.0.0.1:6379',
        'OPTIONS': {
            'DB': 3,
            'PASSWORD': '',
            'PARSER_CLASS': DefaultParser
        },
    },
}

ImportError: No module named cacheops

After I install CacheOps and configure it, every request raises ImportError without breaking anything on site. Seems very odd that autodiscover() somehow involved.
CacheOps module is first in INSTALLED_APPS. Everything seems ok, but I suppose that if CACHEOPS have an “all” value for “.” key it might be the reason. I know that in real world it is stupid to do config like this, but it was a test and you may be interested in results.

Traceback (most recent call last):

 File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 101, in get_response
   request.path_info)

 File "/usr/local/lib/python2.6/dist-packages/django/core/urlresolvers.py", line 250, in resolve
   for pattern in self.url_patterns:

 File "/usr/local/lib/python2.6/dist-packages/django/core/urlresolvers.py", line 279, in _get_url_patterns
   patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)

 File "/usr/local/lib/python2.6/dist-packages/django/core/urlresolvers.py", line 274, in _get_urlconf_module
   self._urlconf_module = import_module(self.urlconf_name)

 File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
   __import__(name)

 File "/var/www/launchnow/urls.py", line 9, in <module>
   admin.autodiscover()

 File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/__init__.py", line 22, in autodiscover
   mod = import_module(app)

 File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
   __import__(name)

ImportError: No module named cacheops

"wrong number of arguments for 'watch' command" error

Wanted to try the library but no luck, got this exception:

Django Version: 1.4
Exception Type: ResponseError
Exception Value: ERR wrong number of arguments for 'watch' command
Redis Version: 2.4.4
redis==2.4.9 in requirements.txt

When doing object.save() for "get" cached model.

Can put zipped error page to some file hosting for investigation.

can't cache model methods

I'm not sure if caching model methods is an existing capability, or whether it should be. When I decorate a method of a model class with @cached(timeout=60), and then I call the instance method, it seems to try and cache the model instance rather than the method. I get this error:

'MyModel' object has no attribute 'name'

Exception Location: /usr/lib/python2.7/functools.py in update_wrapper, line 33

cant use ./manage.py invalidate command by default after pip install

After installing the library through pip, in the application directory (cacheops) there is no directory "managment/commands" which must contain a file invalidate.py with the command invalidate for use in "./manage.py invalidate <all | obj | ...>" This is not a mistake?

cd .virtualenv/lib/python2.7/site-packages/cacheops/
ls -l
-rw-r--r-- 1 sq wheel 154 Dec 24 13:26 init.py
-rw-r--r-- 1 sq wheel 1939 Dec 24 13:26 conf.py
-rw-r--r-- 1 sq wheel 6389 Dec 24 13:26 invalidation.py
-rw-r--r-- 1 sq wheel 2408 Dec 24 13:26 jinja2.py
-rw-r--r-- 1 sq wheel 0 Dec 24 13:26 models.py
-rw-r--r-- 1 sq wheel 20079 Dec 24 13:26 query.py
-rw-r--r-- 1 sq wheel 4199 Dec 24 13:26 simple.py
-rw-r--r-- 1 sq wheel 4172 Dec 24 13:26 utils.py

no managment/commands here

Invalidation problem

Заметил такое странное поведение при инвалидации кэша.

  1. Стартую приложение
  2. Делаю запрос к вьюхе, в которой есть обращение к БД
    b = Brand.objects.get(slug='slug_key')
  3. redis-cli показывает:
    redis 127.0.0.1:6379[2]> smembers "schemes:catalog.brand"
    1. "slug"
    2. "id"
  4. Делаю flushdb
  5. Повторяю запрос п. 2
  6. Ключи для инвалидации не создаются
    redis 127.0.0.1:6379[2]> smembers "schemes:catalog.brand"
    (empty list or set)

Хотя в кэше они есть:

redis 127.0.0.1:6379[2]> keys brand

  1. "conj:catalog.brand:id=1"
  2. "conj:catalog.brand:slug=slug_key"

Что можно сделать, чтобы запросы по slug=*** проходили инвалидацию?

Cacheops crashes the entire application if for some reason it cannot connect to the configured Redis server

First of all, I really like how this library works, it's really great stuff!

However I did run into the problem described in the title.
This is dangerous behaviour on production, if your cache becomes unreachable for some reason then it will kill the entire application. It should instead continue along happily though obviously with degraded application performance. And ideally raising some visible warning that will alert admins.

With Django's core cache modules for example, if you kill the memcache machines that are configured to be used in settings, the application will keep working fine.

Example:

File "/Users/bberes/Sites/coveapi/django-cacheops/cacheops/query.py", line 411, in _post_save
invalidate_obj(instance)
File "/Users/bberes/Sites/coveapi/django-cacheops/cacheops/invalidation.py", line 163, in invalidate_obj
invalidate_from_dict(non_proxy(obj.class), obj.dict)
File "/Users/bberes/Sites/coveapi/django-cacheops/cacheops/invalidation.py", line 122, in invalidate_from_dict
schemes = cache_schemes.schemes(model)
File "/Users/bberes/Sites/coveapi/django-cacheops/cacheops/invalidation.py", line 61, in schemes
return self.load_schemes(model)
File "/Users/bberes/Sites/coveapi/django-cacheops/cacheops/invalidation.py", line 49, in load_schemes
version, members = txn.execute()
File "/Users/bberes/sites/env/coveapi/lib/python2.7/site-packages/redis/client.py", line 1821, in execute
return execute(conn, stack, raise_on_error)
File "/Users/bberes/sites/env/coveapi/lib/python2.7/site-packages/redis/client.py", line 1706, in _execute_transaction
connection.send_packed_command(all_cmds)
File "/Users/bberes/sites/env/coveapi/lib/python2.7/site-packages/redis/connection.py", line 283, in send_packed_command
self.connect()
File "/Users/bberes/sites/env/coveapi/lib/python2.7/site-packages/redis/connection.py", line 231, in connect
raise ConnectionError(self._error_message(e))
ConnectionError: Error 61 connecting localhost:6379. Connection refused.

install_cacheops() fails with Django 1.4

Setup is exactly like in the installation instructions from README.

After adding cacheops cannot even runserver or any manage.py command:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/core/management/base.py", line 209, in execute
    translation.activate('en-us')
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 100, in activate
    return _trans.activate(language)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 202, in activate
    _active.value = translation(language)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 185, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 162, in _fetch
    app = import_module(appname)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/slam/workspace/taobao_shop/satchless/contrib/payment/django_payments_provider/__init__.py", line 5, in <module>
    from . import listeners
  File "/home/slam/workspace/taobao_shop/satchless/contrib/payment/django_payments_provider/listeners.py", line 2, in <module>
    from . import models
  File "/home/slam/workspace/taobao_shop/satchless/contrib/payment/django_payments_provider/models.py", line 3, in <module>
    from payments.models import Payment
  File "/home/slam/workspace/taobao_shop/payments/models.py", line 9, in <module>
    from .robox.handler import payment_failed, payment_received
  File "/home/slam/workspace/taobao_shop/payments/robox/handler.py", line 1, in <module>
    from satchless.order.models import Order
  File "/home/slam/workspace/taobao_shop/satchless/order/__init__.py", line 4, in <module>
    from . import listeners
  File "/home/slam/workspace/taobao_shop/satchless/order/listeners.py", line 1, in <module>
    from satchless.cart.signals import cart_content_changed
  File "/home/slam/workspace/taobao_shop/satchless/cart/__init__.py", line 4, in <module>
    from .handler import AddToCartHandler
  File "/home/slam/workspace/taobao_shop/satchless/cart/handler.py", line 5, in <module>
    from . import forms
  File "/home/slam/workspace/taobao_shop/satchless/cart/forms.py", line 15, in <module>
    class AddToCartForm(forms.Form, QuantityForm):
  File "/home/slam/workspace/taobao_shop/satchless/cart/forms.py", line 19, in AddToCartForm
    quantity = forms.DecimalField(_('Quantity'), initial=1)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 81, in ugettext
    return _trans.ugettext(message)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 286, in ugettext
    return do_translate(message, 'ugettext')
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 276, in do_translate
    _default = translation(settings.LANGUAGE_CODE)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 185, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 162, in _fetch
    app = import_module(appname)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/cacheops/__init__.py", line 8, in <module>
    install_cacheops()
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/cacheops/query.py", line 495, in install_cacheops
    for model in get_models(include_auto_created=True):
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/db/models/loading.py", line 167, in get_models
    self._populate()
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/db/models/loading.py", line 61, in _populate
    self.load_app(app_name, True)
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/db/models/loading.py", line 83, in load_app
    if not module_has_submodule(app_module, 'models'):
  File "/home/slam/.virtualenvs/taobao/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 17, in module_has_submodule
    for entry in package.__path__:  # No __path__, then not a package.
AttributeError: 'module' object has no attribute '__path__'

ResponseError: unknown command 'MULTI'

Hi!

After install cacheopts I have this issue:
unknown command 'MULTI'

Installation process:
sudo apt-get install redis-server
pip install redis
pip install django-cacheops
(later from git: pip install -e git+git://github.com/Suor/django-cacheops.git#egg=django-cacheops)

And my config is default:
CACHEOPS_REDIS = {
'host': 'localhost', # redis-server is on same machine
'port': 6379, # default redis port
'db': 1, # SELECT non-default redis database
# using separate redis db or redis instance
# is highly recommended
'socket_timeout': 3,
}

CACHEOPS = {
# Automatically cache any User.objects.get() calls for 15 minutes
# This includes request.user or post.author access,
# where Post.author is a foreign key to auth.User
'auth.user': ('get', 60*15),

# Automatically cache all gets, queryset fetches and counts
# to other django.contrib.auth models for an hour
'auth.*': ('all', 60*60),

# Enable manual caching on all news models with default timeout of an hour
# Use News.objects.cache().get(...)
#  or Tags.objects.filter(...).order_by(...).cache()
# to cache particular ORM request.
# Invalidation is still automatic
'news.*': ('just_enable', 60*60),

# Automatically cache count requests for all other models for 15 min
'*.*': ('count', 60*15),

}

Here is my traceback: http://dpaste.org/4zTLA/

I'm new to redis, sorry for probably newbie question.
Thanx.

Cacheops don't invalidate on old state when force_update=True is used

Currently fetching old object relies on patching QuerySet.exists() to perform full get and stash a result. Normally .exists() is called in Model.pre_save() which makes things work. The thing is .exists() is not called when force_update=True is used.

Additional misfeature of current hacky approach is slowering all .exists() calls.

Doesn't invalidate for ManyToManyField with through table

class Photo(models.Model):
liked_user = ManyToManyField(User, through="PhotoLike")

class PhotoLike(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
photo = models.ForeignKey(Photo)
timestamp = models.DateTimeField(auto_now_add=True)

user list who likes photo:

Photo.objects.get(pk=1).liked_user.all()
user1, user2

after a new user likes the photo:

PhotoLike.objects.create(user=user3, photo=photo)
Photo.objects.get(pk=1).liked_user.all()
user1, user2
the result is wrong? user3 should be in the result. I see the cache isn't invalidated.
Could you help me?

Exception with Q and subquery - Can't stringify django.db.models.sql.where.SubqueryConstraint

When there a query with Q and subquery cacheops fails with expection.
See code example below.

models

from django.contrib.auth.models import Group
from django.db import models

# Create your models here.
from django.db.models import TextField


class TM(models.Model):
     group = models.ForeignKey(Group, null=True, blank=True)

code

>>> from django.core.cache import cache
>>> from zxczxc.models import *
>>> from django.db.models import Q
>>> from django.contrib.auth.models import Group
>>> qs = TM.objects.filter(Q(group__in=Group.objects.all()) )
>>> cache.set("ttc5", qs)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Users\ShapeR\webadmenv\lib\site-packages\django\core\cache\backends\locmem.py", line 73, in set
    pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
  File "C:\Users\ShapeR\webadmenv\lib\site-packages\django\db\models\query.py", line 66, in __getstate__
    self._fetch_all()
  File "C:\Users\ShapeR\webadmenv\lib\site-packages\django\db\models\query.py", line 854, in _fetch_all
    self._result_cache = list(self.iterator())
  File "C:\Users\ShapeR\webadmenv\lib\site-packages\django_cacheops-1.0.3-py2.7.egg\cacheops\query.py", line 346, in iterator
    cache_key = self._cache_key()
  File "C:\Users\ShapeR\webadmenv\lib\site-packages\django_cacheops-1.0.3-py2.7.egg\cacheops\query.py", line 254, in _cache_key
    md5.update(stringify_query(self.query))
  File "C:\Users\ShapeR\webadmenv\lib\site-packages\django_cacheops-1.0.3-py2.7.egg\cacheops\query.py", line 212, in stringify_query
    raise ValueError(*e.args)
ValueError: Can't stringify <django.db.models.sql.where.SubqueryConstraint object at 0x03369570>

RuntimeError: dictionary changed size during iteration

Hello,

I have a project which extends django-oscar and I use django-cacheops for caching.

While I'm trying to cache my product objects, I'm having the following exception.

RuntimeError                              Traceback (most recent call last)
<ipython-input-1-44863237a714> in <module>()
----> 1 p=Product.objects.get(id=53030)

/Users/aykutozat/dhr/lib/python2.7/site-packages/cacheops/query.pyc in get(self, *args, **kwargs)
    522
    523     def get(self, *args, **kwargs):
--> 524         return self.get_queryset().inplace().get(*args, **kwargs)
    525
    526     def cache(self, *args, **kwargs):

/Users/aykutozat/dhr/lib/python2.7/site-packages/cacheops/query.pyc in get(self, *args, **kwargs)
    414             qs = self
    415
--> 416         return qs._no_monkey.get(qs, *args, **kwargs)
    417
    418     def exists(self):

/Users/aykutozat/dhr/lib/python2.7/site-packages/django/db/models/query.pyc in get(self, *args, **kwargs)
    359         if self.query.can_filter():
    360             clone = clone.order_by()
--> 361         num = len(clone)
    362         if num == 1:
    363             return clone._result_cache[0]

/Users/aykutozat/dhr/lib/python2.7/site-packages/django/db/models/query.pyc in __len__(self)
     83                 self._result_cache = list(self._iter)
     84             else:
---> 85                 self._result_cache = list(self.iterator())
     86         elif self._iter:
     87             self._result_cache.extend(self._iter)

/Users/aykutozat/dhr/lib/python2.7/site-packages/cacheops/query.pyc in iterator(self)
    372
    373         if cache_this:
--> 374             self._cache_results(cache_key, results)
    375         raise StopIteration
    376

/Users/aykutozat/dhr/lib/python2.7/site-packages/cacheops/query.pyc in _cache_results(self, cache_key, results, timeout)
    275     def _cache_results(self, cache_key, results, timeout=None):
    276         cond_dnf = dnf(self)
--> 277         cache_thing(self.model, cache_key, results, cond_dnf, timeout or self._cachetimeout)
    278
    279     def cache(self, ops=None, timeout=None, write_only=None):

/Users/aykutozat/dhr/lib/python2.7/site-packages/cacheops/conf.pyc in _inner(*args, **kwargs)
     34     def _inner(*args, **kwargs):
     35         try:
---> 36             return func(*args, **kwargs)
     37         except redis.ConnectionError, e:
     38             warnings.warn("The cacheops cache is unreachable! Error: %s" % e, RuntimeWarning)

/Users/aykutozat/dhr/lib/python2.7/site-packages/cacheops/query.pyc in cache_thing(model, cache_key, data, cond_dnf, timeout)
     48
     49     # Write data to cache
---> 50     pickled_data = pickle.dumps(data, -1)
     51     if timeout is not None:
     52         txn.setex(cache_key, timeout, pickled_data)

RuntimeError: dictionary changed size during iteration

I only get this error for this particular model(Product). When I try to pickle my product object with pickle rather than cPickle, I don't get this error. I'm not sure the problem is in cPickle or something else, so I need your help.

My Django version is 1.4.10, django-cacheops verson is 1.1 and here is my settings for cacheops.

CACHEOPS_REDIS = {
    'host': 'localhost', # redis-server is on same machine
    'port': 6379,        # default redis port
    'db': 1,             # SELECT non-default redis database
                         # using separate redis db or redis instance
                         # is highly recommended
    'socket_timeout': 3,
}

CACHEOPS = {
    'catalogue.product': ('get', 60*15),
}
CACHEOPS_DEGRADE_ON_FAILURE=True

Thanks.

Feature: Multi-server support

This would be also a very nice thing that I've been seriously looking at.
I think some options would be to integrate a smarter client wrapper instead of redis-py like:
https://github.com/gmr/mredis
https://github.com/salimane/rediscluster-py

Or just implement it directly, with the minimum required feature set for cacheops. I quite like how rediscluster works.
There are some obstacles however.

  1. The straightforward solution is to distribute all cache keys evenly based on the modulo of CRC32 hash. This is handled by the libs above. However the way cacheops works, I suppose the schemas would need to be always stored/updated on every (master) server.
  2. Cacheops uses pipelining in some places which is more tricky to update for multi-server. But should be doable, especially with rediscluster.

Any thoughts on this matter would be appreciated.

Multiple monkey mix not supported

Hello!

First of all, thank you for this great app!

But we have some problems with using it. This issue catched only on staging server, not on local machines.

When we add cacheops to INSTALLED_APPS, your app raise error:

AssertionError at /
Multiple monkey mix not supported

http://dpaste.org/QfoUZ/

I added some log:

logger.debug(cls)
if '_no_monkey' in cls.dict:
--logger.debug('catch')
assert '_no_monkey' not in cls.dict, 'Multiple monkey mix not supported'

and this is output:

DEBUG utils class 'django.db.models.manager.Manager'
DEBUG utils 139989483362048 catch

For now I don't understand this. Could you help me?

TypeError: __new__() takes exactly 3 arguments (2 given)

Hello!

I use django-cacheops method .cache() in my project

One of the model always raise the error: TypeError: new() takes exactly 3 arguments (2 given)

Traceback (most recent call last):
  File "/home/vagrant/my-venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 107, in get_response
    response = middleware_method(request, callback, callback_args, callback_kwargs)
  File "/home/vagrant/my-venv/local/lib/python2.7/site-packages/debug_toolbar/middleware.py", line 73, in process_view
    response = panel.process_view(request, view_func, view_args, view_kwargs)
  File "/home/vagrant/my-venv/local/lib/python2.7/site-packages/debug_toolbar/panels/profiling.py", line 133, in process_view
    return self.profiler.runcall(view_func, *args, **view_kwargs)
  File "/usr/lib/python2.7/cProfile.py", line 149, in runcall
    return func(*args, **kw)
  File "/home/vagrant/my-venv/local/lib/python2.7/site-packages/django/views/generic/base.py", line 69, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/vagrant/my-venv/local/lib/python2.7/site-packages/django/views/generic/base.py", line 87, in dispatch
    return handler(request, *args, **kwargs)
  File "/vagrant/source/ilovei/articles/views.py", line 106, in get
    arts = list(context["object_list"].cache()) #hit
  File "/home/vagrant/my-venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 96, in __iter__
    self._fetch_all()
  File "/home/vagrant/my-venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 854, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/home/vagrant/my-venv/local/lib/python2.7/site-packages/cacheops/query.py", line 367, in iterator
    results = pickle.loads(cache_data)
TypeError: __new__() takes exactly 3 arguments (2 given)

The same if i cache this model by simple cache:

from cacheops import cache
        tmp = None
        try:
            tmp = cache.get("cache_key")
        except CacheMiss:
            print "=====+CacheMiss+====="
        if tmp is None:
            tmp = list(Article.objects.all())
        cache.set("cache_key", tmp, timeout=60)

I use Django 1.6.1 and default settings cacheops from reedme.rst. And i don’t have any problems with caching other models in this project

Could you help me to resolve it?

Thank you.

Strange ORM issue

Hello Suor,

I'm having a problem about cacheops.

In [2]: User.objects.get?
Type:       instancemethod
String Form:<bound method UserManager.get of <django.contrib.auth.models.UserManager object at 0x10b1dd590>>
File:       /Users/aykutozat/easy_deneme/lib/python2.7/site-packages/cacheops/query.py
Definition: User.objects.get(self, *args, **kwargs)
Docstring:  <no docstring>

In [3]: User.objects.filter?
Type:       instancemethod
String Form:<bound method UserManager.filter of <django.contrib.auth.models.UserManager object at 0x10b1dd590>>
File:       /Users/aykutozat/easy_deneme/lib/python2.7/site-packages/django/db/models/manager.py
Definition: User.objects.filter(self, *args, **kwargs)
Docstring:  <no docstring>

You can see that get method of User manager points to cacheops. However I didn't set any cache behavior for User and even for no other models. Here is my settings:

CACHEOPS_REDIS = {
    'host': 'localhost',  # redis-server is on same machine
    'port': 6379,         # default redis port
    'db': 1,              # SELECT non-default redis database
                          # using separate redis db or redis instance
                          # is highly recommended
    'socket_timeout': 3,
}

CACHEOPS = {
}

CACHEOPS_DEGRADE_ON_FAILURE = True

The biggest problem I have about this issue is below.

class ProductReview(models.Model):
    product = models.ForeignKey(
        'catalogue.Product', related_name='reviews', null=True,
        on_delete=models.SET_NULL)

class Product(models.Model):
    ....

When I try to query reviewsover any product instance, .getqueries to all table. Even I have no cacheops settings for productreview, its .get comes from under cacheops/query.py just like User above.

Here is an example to make my point more clear.

In [1]: p=Product.objects.get(id=129037)

In [2]: p.reviews.get(status=0)
Out[2]: <ProductReview: Deneme>

SELECT "reviews_productreview"."id", .... 
FROM "reviews_productreview" WHERE "reviews_productreview"."status" = 0

You see that there is no condition for product_id at where clause. When I remove cacheops from my installed-apps here is the result.

In [1]: p=Product.objects.get(id=129037)

In [2]: p.reviews.get(status=0)

SELECT "reviews_productreview"."id", ... 
FROM "reviews_productreview" WHERE ("reviews_productreview"."product_id" = 129037  AND "reviews_productreview"."status" = 0 )

When I debug the problem, I've headed to get method under ManagerMixin which queries the only given kwargs. However, even I didn't want cacheops to cache the ProductReview or User, why it still overlaps their .get?

Thanks.

Auth.users cannot be cached automatically

_cacheprofile is not attatched to auth.users in Django 1.3

I'm unsure why this is true. My work around is to manually instantiate _cacheprofile in my apps models.py

from django.contrib.auth.models import User
User._cacheprofile = {'local_get': False,
                      'timeout': 3600, # 1 Hour
                      'ops': set(['count', 'fetch', 'get'])}

Configuring cacheops

Hi--

I'm using cacheops and it is awesome. I'm still relatively new to it, so am trying to figure out the best configuration to keep as many things as possible in the cache since we are having a massive uptick in traffic and the site is still quite slow. I had an issue before where I had MAX_ENTRIES set to 1000 so it did not keep entries in the cache for very long. Now, I'm thinking it may just be better to keep items in the cache for longer? I've also tried looking at the maxmemory settings in the redis config --- there are still < 100k items in the cache but things still seem to get evicted. Any tips on the best way to configure it if I just want to cache as much as possible?

CACHEOPS = {
    '*.*': ('all', 60 * 60),
 }

CACHEOPS_DEGRADE_ON_FAILURE = True

CACHES = {
    "default": {
        "BACKEND": "redis_cache.cache.RedisCache",
        "LOCATION": "127.0.0.1:6379:1",
        "OPTIONS": {
        "CLIENT_CLASS": "redis_cache.client.DefaultClient",
        "MAX_ENTRIES": 1000000,
       }
   }

}

using models in middleware at apache mod_wsgi breaks all

settings.py

CACHEOPS_REDIS = {
    'host': 'localhost',
    'port': 6379,
    'db': 1,
}

CACHEOPS = {
    '*.*': ('all', 60*60*24),
}

traceback

django/core/handlers/base.py", line 47, in load_middleware
raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
ImproperlyConfigured: Error importing middleware xxx.middleware: "cannot import name Xxx"

in middleware just

from xxx.models.imort *

at development server everything is ok

cache_on_save is not working as expected

Hello!
I try to use cache_on_save feature.
In settings.py:

CACHEOPS = {
    'app.model': ('all', DEFAULT_CACHE_TIME, {"cache_on_save": "video"})
}

Model object cached after saving by key conj:app.model:video_id=1 - all right.
But in the next calling of get function (Model.objects.get(video=1)), Model is retrieved from database, not from cache.

It happens because _cache_key return diffrent keys.
That's because when Model is cached after saving we have in _cache_key function:

extra = "cacheops.query.<lambda>"
self.query.default_ordering == True
self.query.used_aliases == set(["app_model"])

But when Model retrieve:

extra = ""
self.query.default_ordering == False
self.query.used_aliases == set([])

Are Django's cache framework and django-cacheops mutually exclusive?

Can I use Django's cache framework at the same time as django-cacheops?

I would like to still use the Django's cache framework, with memcached backend, to do some page's caching, while using django-cacheops as ORM cache.

Is there any problem? Should I do otherwise? Is it counterproductive?

cacheops is not thread safe

It was never designed to be, but now that some folks are trying to use it with threads, I create this issue.

There are two things that can go wrong:

  • accidental WatchErrors described in #9
  • corruption of cache_schemes since schemes and their version update is not atomic
    (there are more shared objects, but they should not cause any issues)

The first problem should be addressed in pooling_refactor branch, second is highly unlikely to appear. Can anyone test it some real application using threads?

Does many to many work

I am using InheritanceManager [django-model-utils] for a few of my models.

I have a 'Folder' model and then a base 'Media' model.
The folder has a many to many to the Media

Then I have a few implementations of Media i.e Image, Document etc. Not sure if this is really an issue but when I create a new instance of Document lets say and add it to the folders many to many relationship, it doesn't seem to invalidate or im missing something.

Here is the result in shell. This might help.

folder.media.all()
Media: Media object, Media: Media object, Media: Media object, Media: Media object

list(folder.media.all())
Media: Media object, Media: Media object

The django rendering seems to do the latter looks like cause I only see two in the objects in template.

Any ideas? Thanks.

Invalidate cached function

Hi, if I cache a function with

@cached()
def start_time(flight):
    outp = complicated_stuff(flight.x)
    return outp

Is there an easy way I can invalidate it?

3rd party apps breaking

Been using this app called feedjack (http://www.feedjack.org/) to grab feeds

Traceback (most recent call last):
  File "feedjack_update.py", line 505, in <module>
    main()
  File "feedjack_update.py", line 488, in main
    for feed in models.Feed.objects.filter(is_active=True):
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 107, in _result_iter
    self._fill_cache()
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 772, in _fill_cache
    self._result_cache.append(self._iter.next())
  File "/usr/local/lib/python2.6/dist-packages/cacheops/query.py", line 301, in iterator
    cache_this = self._cacheprofile is not None and 'fetch' in self._cacheops
AttributeError: 'QuerySet' object has no attribute '_cacheprofile'

I'm not caching any of the feed jack models

CACHEOPS = {
    'pad.padportfoliothumb': ('all', 60*60),
    'pad.*':  ('just_enable', 60*60),
}

Error on production

Hello Suor,

I'm getting the following error on production only (sending an email works fine locally):

  File "/home/deploy/corgi/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)

  File "/home/deploy/corgi/corgiapp/decorators.py", line 70, in validate_logged_in
    return fn(request, *args, **kwargs)

  File "/home/deploy/corgi/corgiapp/decorators.py", line 14, in validate_corgi
    return fn(request, corgi_user, *args, **kwargs)

  File "/home/deploy/corgi/corgiapp/decorators.py", line 56, in validate_instructor_or_ta
    return fn(request, corgi_user, *args, **kwargs)

  File "/home/deploy/corgi/corgiapp/views/roster.py", line 48, in roster
    send_email.send_added_to_corgi_email(request, corgi_users)

  File "/home/deploy/corgi/corgiapp/views/send_email.py", line 122, in send_added_to_corgi_email
    _send_added_to_corgi_email(request, send_to)

  File "/home/deploy/corgi/corgiapp/views/send_email.py", line 61, in _send_added_to_corgi_email
    current_site = get_current_site(request)

  File "/home/deploy/corgi/venv/local/lib/python2.7/site-packages/django/contrib/sites/models.py", line 95, in get_current_site
    current_site = Site.objects.get_current()

  File "/home/deploy/corgi/venv/local/lib/python2.7/site-packages/django/contrib/sites/models.py", line 26, in get_current
    current_site = self.get(pk=sid)

  File "/home/deploy/corgi/venv/local/lib/python2.7/site-packages/cacheops/query.py", line 532, in get
    return self.get_queryset().inplace().get(*args, **kwargs)

  File "/home/deploy/corgi/venv/local/lib/python2.7/site-packages/cacheops/query.py", line 423, in get
    return qs._no_monkey.get(qs, *args, **kwargs)

  File "/home/deploy/corgi/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 382, in get
    num = len(clone)

  File "/home/deploy/corgi/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 90, in __len__
    self._result_cache = list(self.iterator())

  File "/home/deploy/corgi/venv/local/lib/python2.7/site-packages/cacheops/query.py", line 381, in iterator
    self._cache_results(cache_key, results)

  File "/home/deploy/corgi/venv/local/lib/python2.7/site-packages/cacheops/query.py", line 284, in _cache_results
    cache_thing(self.model, cache_key, results, cond_dnf, timeout or self._cachetimeout)

  File "/home/deploy/corgi/venv/local/lib/python2.7/site-packages/cacheops/query.py", line 67, in cache_thing
    txn.expire(conj_key, model._cacheprofile['timeout'] + 10)

AttributeError: type object 'Site' has no attribute '_cacheprofile'

In case it's useful, my settings are:

CACHEOPS_REDIS = {
   'host': 'localhost',
   'port': 6379,
   'db': 1,
   'socket_timeout': 3,
}

CACHEOPS = {
   'auth.user': ('get', 60*15),
   'auth.*': ('all', 60*60),
   '*.*': ('all', 60*120),
}

Any ideas what the issue may be? Cacheops is working well in other parts of the code. Thanks in advance.

Can't encode Decimal

Hi, I have a problems, when I try to filter results by Decimal filed.
I'm getting following error:
TypeError: Can't encode Decimal('7')
Stack:
cacheops/query.py in stringify_query

            raise TypeError("Can't encode %s" % repr(obj))
    def stringify_query(query):
        return json.dumps(query, default=encode_object, skipkeys=True, sort_keys=True, separators=(',',':'))
    return stringify_query

models.py:

    class ModelName(...):
        field = models.DecimalField(blank=True, default=0.0)

views.py:

    def view(...):
        ModelName.objects.distinct().filter(field__range=[1.0, 10.0])

Can u fix it?

ManyToMany models problem in Django Admin users management

If I’ve changed something about Django user in Admin, it’ll raise exception about m2m instance have no “_cacheprofile” attribute.
CacheOps config contain 3 rows from documentation expamles that related to user model:

CACHEOPS = {
    'auth.user': ('get', 60*15),
    'auth.*': ('all', 60*60),
    # 'my_apps.*': ('all', 60*30),   
    '*.*': ('count', 60*15),
}
Traceback (most recent call last):

 File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 111, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/options.py", line 307, in wrapper
   return self.admin_site.admin_view(view)(*args, **kwargs)

 File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py", line 93, in _wrapped_view
   response = view_func(request, *args, **kwargs)

 File "/usr/local/lib/python2.6/dist-packages/django/views/decorators/cache.py", line 79, in _wrapped_view_func
   response = view_func(request, *args, **kwargs)

 File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/sites.py", line 197, in inner
   return view(request, *args, **kwargs)

 File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py", line 28, in _wrapper
   return bound_func(*args, **kwargs)

 File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py", line 93, in _wrapped_view
   response = view_func(request, *args, **kwargs)

 File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py", line 24, in bound_func
   return func(self, *args2, **kwargs2)

 File "/usr/local/lib/python2.6/dist-packages/django/db/transaction.py", line 217, in inner
   res = func(*args, **kwargs)

 File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/options.py", line 983, in change_view
   form.save_m2m()

 File "/usr/local/lib/python2.6/dist-packages/django/forms/models.py", line 82, in save_m2m
   f.save_form_data(instance, cleaned_data[f.name])

 File "/usr/local/lib/python2.6/dist-packages/django/db/models/fields/related.py", line 1149, in save_form_data
   setattr(instance, self.attname, data)

 File "/usr/local/lib/python2.6/dist-packages/django/db/models/fields/related.py", line 745, in __set__
   manager.clear()

 File "/usr/local/lib/python2.6/dist-packages/django/db/models/fields/related.py", line 519, in clear
   self._clear_items(self.source_field_name)

 File "/usr/local/lib/python2.6/dist-packages/django/db/models/fields/related.py", line 641, in _clear_items
   source_field_name: self._pk_val

 File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 444, in delete
   collector.collect(del_query)

 File "/usr/local/lib/python2.6/dist-packages/django/db/models/deletion.py", line 146, in collect
   reverse_dependency=reverse_dependency)

 File "/usr/local/lib/python2.6/dist-packages/django/db/models/deletion.py", line 91, in add
   if not objs:

 File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 113, in __nonzero__
   iter(self).next()

 File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 107, in _result_iter
   self._fill_cache()

 File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 772, in _fill_cache
   self._result_cache.append(self._iter.next())

 File "/usr/local/lib/python2.6/dist-packages/cacheops/query.py", line 341, in iterator
   self._cache_results(cache_key, results)

 File "/usr/local/lib/python2.6/dist-packages/cacheops/query.py", line 241, in _cache_results
   cache_thing(self.model, cache_key, results, cond_dnf, timeout=self._cachetimeout)

 File "/usr/local/lib/python2.6/dist-packages/cacheops/query.py", line 54, in cache_thing
   txn.expire(conj_key, model._cacheprofile['timeout'] + 10)

AttributeError: type object 'User_groups' has no attribute '_cacheprofile'

Result of generation conj_cache_key may be different for boolean fields

> users = User.objects.filter(is_active=False)
> len(users) 
#0 

> user = User.objects.get(pk=1)
> user.is_active 
# True

> user.is_active = False
> user.save()
> user.is_active 
# False

> users = User.objects.filter(is_active=False)
> len(users) 
#0

User.objects.filter(is_active=False) generate conj_cache_key = "conj:auth.user:is_active=False"

user.save(), while invalidation, generate conj_cache_keys for old and new version of user = "conj:auth.user:is_active=1" and "conj:auth.user:is_active=0"

"conj:auth.user:is_active=False" is not equal "conj:auth.user:is_active=1" and is not equal "conj:auth.user:is_active=0"
so len(users) returns cached result = 0 but must be 1

I think bool values must be converted to int values
in
conj_cache_key_from_scheme() (invalidation.py)
and in _dnf(where) (utils.py)

Exception on trying to cache models with OneToOneRel

When i'm trying to cache my models which contains OneToOneField i`m getting this exception:

for obj in iter:\n\n File "C:\Users\ShapeR\webadmenv\lib\site-packages\cacheops\query.py", line 347, in iterator\n cache_key = self._cache_key()\n\n File "C:\Users\ShapeR\webadmenv\lib\site-packages\cacheops\query.py", line 255, in _cache_key\n md5.update(stringify_query(self.query))\n\n File "C:\Users\ShapeR\webadmenv\lib\site-packages\cacheops\query.py", line 213, in stringify_query\n raise ValueError(*e.args)\n\nValueError: Can't stringify django.db.models.fields.related.OneToOneRel object at 0x047918B0}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.