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

CMSPlugin reduce function breaks in django 1.8 #5405

Closed
sunfirester opened this issue Jun 13, 2016 · 1 comment
Closed

CMSPlugin reduce function breaks in django 1.8 #5405

sunfirester opened this issue Jun 13, 2016 · 1 comment
Assignees
Milestone

Comments

@sunfirester
Copy link

sunfirester commented Jun 13, 2016

I have been working with pickling/caching models on my site recently. I am forced to work with django 1.8 since it is the TLS version. It seems that "model_unpickle" was changed in django 1.9, and djangocms changed to reflect that change. The problem is that pickling models now breaks with django 1.8. I have overwritten the "reduce" function in my models, but perhaps a better solution is needed.

I figured I would at least create an issue so other people would be aware. Here is what I did with my reduce function:

overwritten the way a model is pickled so that we can pass a deffered_class_factory

from django.db.models.query_utils import DeferredAttribute, deferred_class_factory
def __reduce__(self):
    """
    Provide pickling support. Normally, this just dispatches to Python's
    standard handling. However, for models with deferred field loading, we
    need to do things manually, as they're dynamically created classes and
    only module-level classes can be pickled by the default path.
    """
    data = self.__dict__
    # The obvious thing to do here is to invoke super().__reduce__()
    # for the non-deferred case. Don't do that.
    # On Python 2.4, there is something wierd with __reduce__,
    # and as a result, the super call will cause an infinite recursion.
    # See #10547 and #12121.
    deferred_fields = [f for f in self._meta.fields
                       if isinstance(self.__class__.__dict__.get(f.attname),
                                     DeferredAttribute)]
    model = HeaderLink
    return (model_unpickle, (model, deferred_fields, deferred_class_factory), data)
@czpython
Copy link
Contributor

@sunfirester
Thanks for reporting. I'll investigate further.

@czpython czpython self-assigned this Jun 20, 2016
@czpython czpython added this to the 3.3.1 milestone Jun 20, 2016
czpython added a commit to czpython/django-cms that referenced this issue Jun 20, 2016
czpython added a commit to czpython/django-cms that referenced this issue Jun 20, 2016
czpython added a commit that referenced this issue Jun 20, 2016
Fixes #5405 -- Let Django handle pickling
evildmp pushed a commit to evildmp/django-cms that referenced this issue Jun 23, 2016
evildmp pushed a commit to evildmp/django-cms that referenced this issue Jun 23, 2016
evildmp pushed a commit to evildmp/django-cms that referenced this issue Jul 2, 2016
evildmp pushed a commit to evildmp/django-cms that referenced this issue Jul 2, 2016
evildmp pushed a commit to evildmp/django-cms that referenced this issue Jul 2, 2016
evildmp pushed a commit to evildmp/django-cms that referenced this issue Jul 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants