Error Value: can't pickle function objects
What does that error mean? In my main class I have : main_page=PageTemplateFile('zpt/main_page.zpt',globals()) main_page._owner=None def index_html(self,REQUEST=None): """our main page... Enter here!""" if REQUEST is not None: if REQUEST.has_key('YSURLARGS'): if REQUEST['YSURLARGS'][0] == 'domain': self.domain = self.ddb.getDomain(REQUEST['YSURLARGS'][1]) self.domainTitle=self.domain.getHTMLDomainName() else: pass else: pass else: pass return self.main_page(self,REQUEST) And this results in: Site Error An error was encountered while publishing this resource. Error Type: TypeError Error Value: can't pickle function objects
On Friday 28 May 2004 08:36 am, Mohamed Lrhazi wrote:
What does that error mean?
In my main class I have :
main_page=PageTemplateFile('zpt/main_page.zpt',globals()) main_page._owner=None
def index_html(self,REQUEST=None): """our main page... Enter here!""" if REQUEST is not None: if REQUEST.has_key('YSURLARGS'): if REQUEST['YSURLARGS'][0] == 'domain': self.domain = self.ddb.getDomain(REQUEST['YSURLARGS'][1]) self.domainTitle=self.domain.getHTMLDomainName() else: pass else: pass else: pass return self.main_page(self,REQUEST)
And this results in:
Site Error An error was encountered while publishing this resource.
Error Type: TypeError Error Value: can't pickle function objects
Interesting, in my experience (as noted in a very recent post), this means that you are trying to add a function/method as an attribute of an class instance stored in the ZODB. Looking at your code, I see nothing obvious that youd indicate such behavior, unless the getDomain or getHTMLDomainName calls return functions (that seems unlikely judging by their names). Perhaps some other code from this class is at fault? As a side note, in the past I believe that was able to store functions as instance attributes in the ZODB, without any pickling errors. Perhaps in the switch to Zope 2.7, or more likely Python 2.3 this changed. My current suspicion is that it is related to the ZODB's inability to deal properly with "new style" classes. Sorry I can't be of any more help. Good luck, Alec Mitchell
On Friday 28 May 2004 08:36 am, Mohamed Lrhazi wrote:
What does that error mean?
In my main class I have :
main_page=PageTemplateFile('zpt/main_page.zpt',globals()) main_page._owner=None
def index_html(self,REQUEST=None): """our main page... Enter here!""" if REQUEST is not None: if REQUEST.has_key('YSURLARGS'): if REQUEST['YSURLARGS'][0] == 'domain': self.domain = self.ddb.getDomain(REQUEST['YSURLARGS'][1]) self.domainTitle=self.domain.getHTMLDomainName() else: pass else: pass else: pass return self.main_page(self,REQUEST)
And this results in:
Site Error An error was encountered while publishing this resource.
Error Type: TypeError Error Value: can't pickle function objects
Interesting, in my experience (as noted in a very recent post), this means that you are trying to add a function/method as an attribute of an class instance stored in the ZODB. Looking at your code, I see nothing obvious that youd indicate such behavior, unless the getDomain or getHTMLDomainName calls return functions (that seems unlikely judging by their names). Perhaps some other code from this class is at fault? As a side note, in the past I believe that was able to store functions as instance attributes in the ZODB, without any pickling errors. Perhaps in the switch to Zope 2.7, or more likely Python 2.3 this changed. My current suspicion is that it is related to the ZODB's inability to deal properly with "new style" classes. Sorry I can't be of any more help. Good luck, Alec Mitchell
When I replace : self.domain = self.ddb.getDomain(REQUEST['YSURLARGS'][1]) self.domainTitle=self.domain.getHTMLDomainName() with this: domain = self.ddb.getDomain(REQUEST['YSURLARGS'][1]) self.domainTitle=domain.getHTMLDomainName() It works. "domain" above is an instance of a class called Domain, I defined it in a module that lives in /usr/local/zope/lib/python/YSDomain and that does not implement nor extend any Zope classes or interfaces... Why does instantiating such an object inside my zope application cause "can't pickle function objects" error? Thanks a lot. Mohamed~ --On Friday, May 28, 2004 11:36 AM -0400 Mohamed Lrhazi <mohamed@your-site.com> wrote:
What does that error mean?
In my main class I have :
main_page=PageTemplateFile('zpt/main_page.zpt',globals()) main_page._owner=None
def index_html(self,REQUEST=None): """our main page... Enter here!""" if REQUEST is not None: if REQUEST.has_key('YSURLARGS'): if REQUEST['YSURLARGS'][0] == 'domain': self.domain = self.ddb.getDomain(REQUEST['YSURLARGS'][1]) self.domainTitle=self.domain.getHTMLDomainName() else: pass else: pass else: pass return self.main_page(self,REQUEST)
And this results in:
Site Error An error was encountered while publishing this resource.
Error Type: TypeError Error Value: can't pickle function objects
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Friday 28 May 2004 10:15 am, Mohamed Lrhazi wrote:
When I replace :
self.domain = self.ddb.getDomain(REQUEST['YSURLARGS'][1]) self.domainTitle=self.domain.getHTMLDomainName()
with this:
domain = self.ddb.getDomain(REQUEST['YSURLARGS'][1]) self.domainTitle=domain.getHTMLDomainName()
It works.
"domain" above is an instance of a class called Domain, I defined it in a module that lives in /usr/local/zope/lib/python/YSDomain and that does not implement nor extend any Zope classes or interfaces...
Why does instantiating such an object inside my zope application cause "can't pickle function objects" error?
By setting self.domain you are causing the 'domain' instance to be stored in the ZODB, as an attribute of your persistent class. There is apparently some aspect of that 'domain' instance which is not picklable. Unless you really wanted to store/update an instance of that class in the ZODB as an attribute of your Zope object every time you called index_html, the second method is certainly best. Updating that attribute on every call could result in tremendous database bloat. Actually, it seems pretty strange that you are setting any instance attributes during the index_html call, which one wouldn't normally expect to have any side effects. Alec Mitchell
I am learning more and more... getting there :) Thanks a lot Alec. Mohamed~ --On Friday, May 28, 2004 11:07 AM -0700 Alec Mitchell <apm13@columbia.edu> wrote:
On Friday 28 May 2004 10:15 am, Mohamed Lrhazi wrote:
When I replace :
self.domain = self.ddb.getDomain(REQUEST['YSURLARGS'][1]) self.domainTitle=self.domain.getHTMLDomainName()
with this:
domain = self.ddb.getDomain(REQUEST['YSURLARGS'][1]) self.domainTitle=domain.getHTMLDomainName()
It works.
"domain" above is an instance of a class called Domain, I defined it in a module that lives in /usr/local/zope/lib/python/YSDomain and that does not implement nor extend any Zope classes or interfaces...
Why does instantiating such an object inside my zope application cause "can't pickle function objects" error?
By setting self.domain you are causing the 'domain' instance to be stored in the ZODB, as an attribute of your persistent class. There is apparently some aspect of that 'domain' instance which is not picklable. Unless you really wanted to store/update an instance of that class in the ZODB as an attribute of your Zope object every time you called index_html, the second method is certainly best. Updating that attribute on every call could result in tremendous database bloat. Actually, it seems pretty strange that you are setting any instance attributes during the index_html call, which one wouldn't normally expect to have any side effects.
Alec Mitchell
participants (2)
-
Alec Mitchell -
Mohamed Lrhazi