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

Support for @method_decorator in Python 3.5 and later #87

Open
benwhalley opened this issue May 28, 2020 · 2 comments
Open

Support for @method_decorator in Python 3.5 and later #87

benwhalley opened this issue May 28, 2020 · 2 comments

Comments

@benwhalley
Copy link

At present using this inside a class based view:

@method_decorator(cacheback(lifetime=60))
def get_context_data(...):
    ...

Causes an error: AttributeError: 'functools.partial' object has no attribute '__module__'

The error arises in jobs.prepare_args which uses ("%s:%s" % (fn.__module__, fn.__name__),) + args to serialise the function for the queue. The suggestion here: https://stackoverflow.com/questions/20594193/dynamically-created-method-and-decorator-got-error-functools-partial-object-h

Is that in python 3.5 and later a reference to the original function is maintained in the partial. You can access it as .func.

@stephrdev
Copy link
Collaborator

Interesting issue. Besides not knowing if this would work if the partial issue is fixed, the partial issue by itself is worth being fixed. I'm more than happy to review and merge any pull request fixing that issue. Sadly, I won't be able to provide a fix soon.

@Beenhakker
Copy link

Beenhakker commented Jun 1, 2022

I stumbled upon the same problem.

As a workaround (in my case), you can do:

class SomeJob(Job):
    lifetime = 600

    def fetch(self):
        return something()

    def key(self):
        return self.class_path

some_function = SomeJob().get()

Only downside is, is that you cannot wrap a get function from a class based view, so I went one level lower to the function that really needed some caching.

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