Opened on 04/29/2015 at 12:00:32 PM
Closed on 04/30/2015 at 08:41:01 PM
#2434 closed defect (fixed)
[cms] Custom filters and global functions can not be instance methods
Reported by: | sebastian | Assignee: | sebastian |
---|---|---|---|
Priority: | P3 | Milestone: | |
Module: | Sitescripts | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | Platform: | Unknown | |
Ready: | yes | Confidential: | no |
Tester: | Verified working: | no | |
Review URL(s): |
Description
How to reproduce
Create following file with the name foobar.py either in the globals or filters subdirectory:
class Foo: def bar(self): return 42 foobar = Foo().bar
Observed behaviour
You get following Python exception when generating pages or running the development server:
AttributeError: 'instancemethod' object has no attribute 'module_ref'
The cms assigns the module to an attribute of the function to prevent the module from beeing cleaned up, while the function might still be called. But it's not possible to dynamically add attributes to instance methods.
Expected behaviour
It should be possible to use instance methods as template filters and functions. Therefore the module should be persisted in a way that doesn't involve adding an attribute to the function.
https://hg.adblockplus.org/cms/rev/288ade7ccb1d